前端之家收集整理的这篇文章主要介绍了
beans.xml,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd" default-autowire="byName" default-lazy-init="true"> <!-- 打开Spring的Annotation
支持 --> <context:annotation-config /> <context:component-scan base-package="com.reptile" /> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations" value="classpath:config.properties" /> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${databaseDriver}" /> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> <!-- 配置连接池的初始值 --> <property name="initialSize" value="${pool.initialSize}" /> <!-- 连接池的最大值 --> <property name="maxActive" value="${pool.maxActive}" /> <!-- 最大空闲时,当经过一个高峰之后,连接池可以将一些用不到的连接释放,一直减少到maxIdle为止 --> <property name="maxIdle" value="${pool.maxIdle}" /> <!-- 当最小空闲时,当连接少于minIdle时会
自动去申请一些连接 --> <property name="minIdle" value="${pool.minIdle}" /> <property name="maxWait" value="${pool.maxWait}" /> <property name="defaultAutoCommit" value="${pool.defaultAutoCommit}" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSession
factorybean"> <property name="dataSource" ref="dataSource" /> <!-- 设置Spring取那个包中查找相应的实体类 --> <property name="packagesToScan" value="com.reptile.bean" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.show_
sql">${hibernate.show_
sql}</prop> <prop key="hibernate.format_
sql">${hibernate.format_
sql}</prop> <prop key="hibernate.query.substitutions">${hibernate.query.substitutions}</prop> <prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop> <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop> <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop> <!-- 字节码 动态
修改字节码,来替换掉java的动态代理,以这种方式对
性能进行优化 --> <prop key="hibernate.bytecode.use_reflection_optimizer">${hibernate.bytecode.use_reflection_optimizer}</prop> <!--配置启用二级缓存(能用来完全
禁止使用二级缓存. 对那些在类的映射定义中指定<cache>的类,会默认开启二级缓存. 取值 true|false ) --> <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop> <!--配置二级缓存的供应商(
自定义的CacheProvider的类名. 取值classname.of.CacheProvider) --> <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop> <!-- 配置 ehcache.xml--> <prop key="net.sf.ehcache.configurationResourceName">${net.sf.ehcache.configurationResourceName}</prop> <!-- 允许
查询缓存,个别
查询仍然需要被设置为可缓存的. 取值 true|false --> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <!-- 强制Hibernate以更人性化的格式将数据存入二级缓存.取值true|false --> <prop key="hibernate.cache.use_structured_entries">${hibernate.cache.use_structured_entries}</prop> <!-- hibernate4 --> <prop key="hibernate.current_session_context_class">${hibernate.current_session_context_class}</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 只对业务逻辑层实施事务 --> <aop:config expose-proxy="true"> <aop:pointcut id="txPointcut" expression="execution(* com.reptile.service..*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="
required" /> <tx:method name="add*" propagation="
required" /> <tx:method name="set*" propagation="
required" /> <tx:method name="update*" propagation="
required" /> <tx:method name="edit*" propagation="
required"/> <tx:method name="merge*" propagation="
required" /> <tx:method name="delete*" propagation="
required" /> <tx:method name="remove*" propagation="
required" /> <tx:method name="init*" propagation="
required" /> <tx:method name="repair" propagation="
required" /> <tx:method name="deleteAndRepair" propagation="
required" /> <tx:method name="get*" propagation="
required" read-only="true" /> <tx:method name="count*" propagation="
required" read-only="true" /> <tx:method name="find*" propagation="
required" read-only="true" /> <tx:method name="list*" propagation="
required" read-only="true" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> <!-- log日志切面 --> <bean id="logInterceptor" class="com.reptile.interceptor.LogInterceptor" /> <aop:config proxy-target-class="true"> <aop:aspect ref="logInterceptor"> <aop:around pointcut="${save} or ${update} or ${edit} or ${delte}" method="invoke" /> </aop:aspect> </aop:config> </beans>
原文链接:https://www.f2er.com/xml/299192.html