使用IDEA整合SSM spring核心配置文件:beans_core.xml/applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans "> <!-- 开启spring的注解模式 1 --> <context:annotation-config/> <!-- 扫描具体的注解包 1 --> <context:component-scan base-package="com.ujiuye.*"></context:component-scan> <!-- 读取外部的数据库连接条件文件 2 --> <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder> <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driverClassName}"></property> <property name="jdbcUrl" value="${jdbc.url}"></property> <property name="user" value="${jdbc.user}"></property> <property name="password" value="${jdbc.password}"></property> </bean> <!-- spring 整合mybatis 使用的工具类 2 --> <bean name="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml"/> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath:mybatis/mapper/*.xml"/> </bean> <!-- 扫描 mapper接口 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.ujiuye.mapper"/> </bean> <!-- 引入spring提供的事务管理 --> <bean name="manager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <tx:advice id="myDriver" transaction-manager="manager"> <tx:attributes> <!--增--> <tx:method name="save*" isolation="READ_COMMITTED" propagation="REQUIRED"/> <tx:method name="add*" isolation="READ_COMMITTED" propagation="REQUIRED"/> <tx:method name="insert*" isolation="READ_COMMITTED" propagation="REQUIRED"/> <!--删--> <tx:method name="delete*" isolation="READ_COMMITTED" propagation="REQUIRED"/> <!--改--> <tx:method name="update*" isolation="READ_COMMITTED" propagation="REQUIRED"/> <!--查--> <tx:method name="get*" isolation="READ_COMMITTED" propagation="REQUIRED"/> <tx:method name="find*" isolation="READ_COMMITTED" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <!-- 那种类型 --> <aop:config> <aop:pointcut id="pc" expression="execution(* com.ujiuye.service.*.*(..))"></aop:pointcut> <aop:advisor advice-ref="myDriver" pointcut-ref="pc"/> </aop:config> </beans>