<?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:tx= "Http://www.springframework.org/schema/tx"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:context= "Http://www.springframework.org/schema/context"xmlns:p= "http://www.springframework.org/schema/p"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp//Www.springframework.org/schema/contexthttp//www.springframework.org/schema/context/spring-context-3.2.xsdhttp//Www.springframework.org/schema/txhttp//www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp//WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOPhttp://www.springframework.org/schema/aop/spring-aop-3.2.xsd"><!--Configure the data source, remember to remove Mybatis-config.xml data source related configuration--<bean id= "DataSource"class= "Com.mchange.v2.c3p0.ComboPooledDataSource" > <property name= "driverclass" value= "Com.mysql.jdbc.Driver"/&G T <property name= "Jdbcurl"value= "jdbc:mysql://localhost:3306/" (database)? useunicode=true&characterencoding=utf-8 "/> <property name=" User "value=" root "/> <property name=" password "value=" root "/> </bean> <!--configuration Session factory-- > <bean id= "sqlsessionfactory"class= "Org.mybatis.spring.SqlSessionFactoryBean" > <property name= "dataSource" ref= "DataSource"/> <PR Operty name= "configlocation" value= "Classpath:mybatis-config.xml"/> <!--configuration Scan load SQL mapping file, remember to remove the Mybatis-config configuration --<property name= "mapperlocations" value= "Classpath:cn/itcast/scm/dao/*.xml"/> </bean> <!--configuration transaction manager, managing data source transactions--<bean id= "TransactionManager"class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" > <property name= "DataSource" ref= " DataSource "/> </bean> <!--configuring transaction notifications-<tx:advice id=" advice "transaction-manager=" transactionm Anager "> <tx:attributes> <!--only handle run-time exceptions by default and can add rollback- for= "Exception/throwable" handles all exceptions or includes errors---<tx:method name= "insert*" propagation= "REQUIRED"rollback- for= "Exception"/> <tx:method name= "update*" propagation= "REQUIRED"rollback- for= "Exception"/> <tx:method name= "delete*" propagation= "REQUIRED"rollback- for= "Exception"/> <tx:method name= "*" propagation= "SUPPORTS"/> </tx:attributes> </tx :advice> <!--Configure the area to be woven into, and then set the transaction boundary at the service layer--<aop:config> <aop:advisor advice-ref= "advice "pointcut= "Execution (* cn.itcast.scm.service.impl.*.* (..))"/> </aop:config> <!--configuration sessiontemplate, packed with tedious data operations- <bean id= "Sqlsessiontemplate"class= "Org.mybatis.spring.SqlSessionTemplate" > <constructor-arg name= "sqlsessionfactory" ref= "Sqlsessionfactory" /> </bean> <!--<context:component-scan base- Package= "*"/>-<!--auto-scan components, to remove controller, they are configured in Spring-mvc.xml, if not removed will affect transaction management. -<context:component-scan base- Package= "Cn.itcast" > <context:exclude-filter type= "Annotation"expression= "Org.springframework.stereotype.Controller"/> </context:component-scan> <!--Configure the converter, for the interface class under the package (including the sub-package) set in Basepackage, if the full class name of the interface class is consistent in the Mapper.xml file and the defined namespace, it will be converted to spring bean, where it is called by @au towired mode will inject interface instance-<beanclass= "Org.mybatis.spring.mapper.MapperScannerConfigurer" > <property name= "sqlsessionfactory" ref= " Sqlsessionfactory "/> <property name=" basepackage "value=" Cn.itcast.scm.dao "/> </bean></beans >
Spring configuration file (SSM framework)