The project uses Springmvc+mybatis + MySQL development, requires transaction management functions, configured as follows
1.service.xml Configuration
<?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:context= "Http://www.springframework.org/schema/context" xmlns:p= "http://www.springframework.org/schema/p" xmlns:tx= "Http://www.springframework.org/schema/tx" xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring- Beans-3.2.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/co Ntext/spring-context-3.2.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/ Spring-tx.xsd "> <context:property-placeholder location=" web-inf/conf/jdbc.properties "/> <context: Component-scan base-package= "dao"/> <!--note, when the annotations are automatically scanned here, do not scan controller--> <context:component-scan base-package= "service"/> <context:component-scan base-package= "model"/> <tx:annotation-driven transaction-manager= "TransactionManager"/>
<!--tx:annotation-driver tag, because this is the annotation transaction, and after this is on, spring scans the identity containing @transactional in all classes below Dao,service,model. and generate the appropriate proxy (by default, the interface-based JDK dynamic agent), I do transactions at the service layer, add @transactional-ID only at the service layer--
<!--configuration Data source-<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" Destroy-me thod= "Close" > <property name= "Driverclass" > <value>${jdbc.driverClassName}</value> </property> <property name= "Jdbcurl" > <value>${jdbc.url}</value> & lt;/property> <property name= "user" > <value>${jdbc.username}</value> </pr operty> <property name= "password" > <value>${jdbc.password}</value> </prop Erty> <!--The minimum number of connections that are kept in the connection pool. --<property name= "Minpoolsize" > <value>5</value> </property> <!--The maximum number of connections that are kept in the connection pool. Default:15--<property name= "Maxpoolsize" > <value>30</value> </propert Y> <!--The number of connections obtained at initialization, the value should be between Minpoolsize and Maxpoolsize. Default:3-<p roperty name= "initialpoolsize" > <value>10</value> </property> <!--maximum idle time , the connection is discarded if it is not used within 60 seconds. If 0, it will never be discarded. default:0--<property name= "MaxIdleTime" > <value>60</value> </property > <!--c3p0 The number of connections that are fetched at the same time when the connection in the connection pool is exhausted. Default:3--<property name= "acquireincrement" > <value>5</value> </prop Erty> <!--The standard parameters of JDBC to control the number of preparedstatements loaded within the data source. However, because the pre-cached statements belong to a single connection instead of the entire connection pool. So setting this parameter takes into account a variety of factors. If both maxstatements and maxstatementsperconnection are 0, the cache is closed. default:0--<property name= "maxstatements" > <value>0</value> </propert Y> <!--Check for idle connections in all connection pools every 60 seconds. default:0--<property name= "Idleconnectiontestperiod" > <value>60</value> </property> <!--defines the number of repeated attempts to obtain a new connection from the database after a failure. Default:30-<propErty name= "acquireretryattempts" > <value>30</value> </property> <!--get connection lost Loser causes any thread that waits for the connection pool to get the connection to throw an exception. However, the data source is still valid and continues to try to get the connection the next time you call Getconnection (). If set to True, the data source will declare broken and permanently shut down after attempting to acquire a connection failure. Default:false--<property name= "Breakafteracquirefailure" > <value>true</value> </property> <!--because of its high performance, use it only when you need it. If set to true then the validity of each connection submission is officer. We recommend using methods such as Idleconnectiontestperiod or automatictesttable to improve the performance of your connectivity tests. Default:false--<property name= "Testconnectiononcheckout" > <value>false</value> </property> </bean> <!--Configuring the JDBC template--<bean id= "JdbcTemplate" class= "Org.springframew Ork.jdbc.core.JdbcTemplate "> <property name=" dataSource "ref=" DataSource "></property> </BEAN&G T <!--mybatis file configuration, scan all mapper files--<bean id= "sqlsessionfactory" class= "Org.mybAtis.spring.SqlSessionFactoryBean "p:datasource-ref=" DataSource "p:configlocation="/web-inf/mybatis/myba Tis.xml "/> <!--configlocation for MyBatis attribute mapperlocations integrated configuration for all mapper--> <!--spring and MyBatis , scan all DAO--<bean class= "org.mybatis.spring.mapper.MapperScannerConfigurer" p:basepackage= "DAO" P:sqlsessionfactorybeanname= "Sqlsessionfactory"/> <!--transaction management of the data source-<bean id= "TransactionManager" class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" p:datasource-ref= "DataSource"/> ;</beans>
2.servlet.xml Configuration
<?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:mvc= "Http://www.springframework.org/schema/mvc" Xmlns:co ntext= "Http://www.springframework.org/schema/context" xsi:schemalocation= "Http://www.springframework.org/schema /beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd HTTP://WWW.SPRINGFRAMEWORK.O RG/SCHEMA/MVC http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd Http://www.springframewor K.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd "> <context:c Omponent-scan base-package= "Controller"/> <!--note, when the annotations are automatically scanned here, do not scan service-to-<context:component-scan Base-package= "DAO"/> <context:component-scan base-package= "model"/> <!--JSON-with <mvc:annota Tion-driven> <mvc:message-cOnverters register-defaults= "true" > <bean class= "Com.alibaba.fastjson.support.spring.FastJsonHttpMessageC Onverter "> <property name=" supportedmediatypes "value=" Text/html;charset=utf-8 "/> & Lt;property name= "Features" > <array> <value>WriteMapNullValue< /value> <value>WriteNullStringAsEmpty</value> </array> </property> </bean> </mvc:message-converters> </mvc:annotation-driven > <!--viewresolver--<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name= "prefix" value= "/views/"/> <property name= "suffix" value= ". jsp"/> < ;p roperty name= "ContentType" > <value>text/html;charset=UTF-8</value> </property> </bean></beans&Gt
3. Check to see if the MySQL engine is InnoDB.
More information to get
SPRINGMVC + myBatis + MySQL full annotation transaction configuration