<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!-- 配置数据源-->
<bean id="jdbcDataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="jdbcUrl">
<value>jdbc:oracle:thin:@127.0.0.1:1521:orcl</value>
</property>
<property name="user">
<value>bbs</value>
</property>
<property name="password">
<value>123</value>
</property>
</bean>
<!-- 配置mybatis的SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="jdbcDataSource" />
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
</bean>
<!-- 配置dao层 -->
<!--<bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.gxa.bj.dao.imp.UserMapper"></property>
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean>-->
<!-- mapper接口的扫描,必须扫描到接口,扫描的原则是:所有扫描进Spring的Mapper对象,它的命名规则: 首字母小写,
后面的都是按照原有的接口名字定义。 比如UserMapper接口扫描到spring里,id名为userMapper -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.gxa.bj.dao.imp"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- <bean id="userInfoService" class="com.gxa.bj.service.UserInfoService">
<property name="userMapper" ref="userMapper"></property>
</bean>
<bean id="typeInfoService" class="com.gxa.bj.service.TypeInfoService">
<property name="typeInfoMapper" ref="typeInfoMapper"></property>
</bean>
<bean id="titleInfoService" class="com.gxa.bj.service.TitleInfoService">
<property name="titleInfoMapper" ref="titleInfoMapper"></property>
</bean> -->
<!-- <context:component-scan base-package="com.gxa.bj.service"></context:component-scan> -->>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="jdbcDataSource"></property>
</bean>
<!-- 事务增强的配置 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get" read-only="true"/>
<tx:method name="add*" rollback-for="Exception"/>
<tx:method name="remove*" rollback-for="Exception"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(public * com.gxa.bj.service.*.*(..))" id="serviceCut"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceCut"/>
</aop:config>
<!-- 扫描service层到spring容器里 -->
<context:component-scan base-package="com.gxa.bj.service"/>