<!-- 自动搜索@Component,@Service,@Repository等标注的类,不搜索@Controller的类,@Controller的类在mvc.xml中搜索-->
<!-- 自动扫描组件,这里要把web下面的 controller去除,他们是在spring3-servlet.xml中配置的,如果不去除会影响事务管理的。 -->
<context:component-scan base-package="custom define package" annotation-config="true">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- enable autowire -->
<context:annotation-config />
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- 启用缓存注解功能 -->
<cache:annotation-driven cache-manager="cacheManager"/>
<!-- define the sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.sqlSessionfactorybean">
<property name="dataSource" ref="c3p0" />
<!-- ORM映射文件 -->
<!-- 自定义mybatis-config.xml -->
<property name="configLocation" value="classpath:/ibatis/mybatis-config.xml" />
</bean>
<!-- sqlMapper与Mapper.xml映射 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- ORM映射文件具体位置:eg:com/prjname/dao.ibatis/sqlMapper -->
<property name="basePackage" value="com/prjname/dao.ibatis/sqlMapper" />
</bean>
<!-- ================================配置事务相关控制================================================= -->
<!-- 数据库连接池 -->
<!-- eg:/WEB-INF/springspring-pool.xml -->
<import resource="classpath:/spring/spring-pool.xml" />
<!-- 事务管理器 -->
<bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="c3p0"></property>
</bean>
<!-- 配置事务特性 -->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="delete*" propagation="required" read-only="false"
rollback-for="java.lang.Exception" />
<tx:method name="insert*" propagation="required" read-only="false"
rollback-for="java.lang.Exception" />
<tx:method name="update*" propagation="required" read-only="false"
rollback-for="java.lang.Exception" />
<tx:method name="modify*" propagation="required" read-only="false"
rollback-for="java.lang.Exception" />
<tx:method name="*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 配置AOP切面 哪些类的方法需要进行事务管理 -->
<aop:config>
<!--把事务控制在Service层 -->
<!-- eg:exceution( public * com.prjname.service.. * ) -->
<aop:pointcut id="allManagerMethod" expression="execution(public * com.prjname.service..*.*(..))" />
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="transactionAdvice" />
</aop:config>
<!-- service层的属性和配置文件读入,多个用逗号隔开 -->
<!-- controller层的属性和配置文件读入,多个用逗号隔开 -->
<context:property-placeholder
location="classpath:/ibatis/jdbc.properties" />
<!-- cacheManager工厂类 --> <bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerfactorybean" p:configLocation="classpath:/cache/ehcache.xml" /> <!-- 声明cacheManager --> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="cacheManagerFactory"/>