<context:component-scan base-package="com.jsu.service,com.jsu.util"/>
<!--配置session工厂-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath:mybatis/*Mapper.xml"/>
<property name="typeAliasesPackage" value="com.jsu.mapper"/>
</bean>
<!--扫描mapper代理对象-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--设置扫描mapper的包-->
<property name="basePackage" value="com.jsu.mapper"/>
<!-- mapper接口需要用到sqlSessionFactory 如果上下文环境只有一个数据源 则不需要配置 -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
<!--配置通知-->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="select*" read-only="true"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update×" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!--配置切面-->
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.jsu.service.impl.*.*(..))"/>
</aop:config>
<!--开启注解-->
<tx:annotation-driven transaction-manager="txManager"/>
以上是我常用的配置的方式