`

application*.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"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
  http://www.springframework.org/schema/context  
   http://www.springframework.org/schema/context/spring-context-2.5.xsd     
http://www.springframework.org/schema/jee      
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">

<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/mysqlDB" />
<context:component-scan base-package="com.xxx" />
<!-- 支持aop注解 -->
<aop:aspectj-autoproxy />
<import resource="quartzConfig*.xml" />
<!--
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/myhib"></property>
<property name="username" value="root"></property>
<property name="password" value="123"></property>
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" destroy-method="close">
<property name="jndiName">
<value>
java:comp/env/jdbc/mysqlDB
</value>
</property>
</bean>
-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<!--
org.hibernate.dialect.DB2Dialect
org.hibernate.dialect.MySQLDialect
org.hibernate.dialect.PostgreSQLDialect
-->
<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect </prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.show_sql">false</prop>
<!-- 缓存策略,数据量不大可不写  -->
<prop key="cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="cache.use_query_cache">false</prop>
<prop key="cache.use_second_level_cache">false</prop>
<prop key="hibernate.jdbc.fetch_size">1</prop>
<prop key="hibernate.jdbc.batch_size">5</prop>
<prop key="hibernate.fetch">true</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.query.factory_class">
org.hibernate.hql.classic.ClassicQueryTranslatorFactory
                   </prop>
</props>
</property>
<property name="packagesToScan">
<value>com.xxx.pojo</value>
</property>
</bean>
<!--hibernateTemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 配置事务管理 -->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" ></property>
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<!-- AOP的配置 -->
<aop:config>
<!-- 切入点 -->
<aop:pointcut expression="execution(public * com.xxx.service.*.*.*(..))" id="businessService" />
<!-- 通知 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="businessService" />
</aop:config>
<!-- 具体的通知 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<!-- <tx:method name="find*" read-only="true" propagation="NOT_SUPPORTED" />-->
<tx:method name="find*" read-only="false" propagation="NOT_SUPPORTED" />
<!-- get开头的方法不需要在事务中运行 。
有些情况是没有必要使用事务的,比如获取数据。
开启事务本身对性能是有一定的影响的
-->
<tx:method name="*" />    <!-- 其他方法在实务中运行 -->
</tx:attributes>
</tx:advice>
</beans>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics