Spring divides transaction management into two categories:
* Programmatic Transaction Management
Write code manually for transaction management, with less in development
* Declarative Transaction Management
A-based on the Transactionproxyfactorybean approach. Development is rarely used
You need to configure a Transactionproxyfactorybean for each class for transaction management to be enhanced
B-based on ASPECTJ XML, Mehsud often uses
Once configured, there is no need to add anything on the class
C-based on annotations, the development of the use of multi-
Simple configuration, need to add a @transaction annotation to the business layer class
Building a spring transactional environment
Create a table and add data
-- ------------------------------Table structure for account-- ----------------------------DROP TABLE IF EXISTS' account ';CREATE TABLE' account ' (' ID ')int( One) not NULL, ' name 'varchar( -) not NULL, ` Money`Double DEFAULT NULL, PRIMARY KEY(' id ')) ENGINE=InnoDBDEFAULTCHARSET=UTF8;-- ------------------------------Records of account-- ----------------------------INSERT into' Account 'VALUES('1','A','1900');INSERT into' Account 'VALUES('2','B',' -');INSERT into' Account 'VALUES('3','C',' +');
Create a Web project and add a configuration file jdbc.properties, log4j.properties
Jdbc.properties
Jdbc.driverclass = Com.mysql.jdbc.Driverjdbc.url = Jdbc:mysql:///spring_transactionjdbc.username = Rootjdbc.password = at
Log4j.properties
log4j.rootlogger=debug,console,file#log4j.rootlogger=error,rolling_filelog4j.logger.cn.jbit.dao= Debuglog4j.logger.com.ibatis=debug Log4j.logger.com.ibatis.common.jdbc.simpledatasource=debug Log4j.logger.com.ibatis.common.jdbc.scriptrunner=debug Log4j.logger.com.ibatis.sqlmap.engine.impl.sqlmapclientdelegate=debug Log4j.logger.java.sql.connection=debug Log4j.logger.java.sql.statement=debug Log4j.logger.java.sql.preparedstatement=debug Log4j.logger.java.sql.resultset=debug log4j.logger.org.tuckey.web.filters.urlrewrite.urlrewritefilter=debug#### ################################################################################### Console Appender \u65e5\u5fd7 \u5728\u63a7\u5236\u8f93\u51fa\u914d\u7f6e#################################################################### ################# #log4j. appender.console=org.apache.log4j.consoleappenderlog4j.appender.threshold= errorlog4j.appender.console.target=system.outlog4j.appender.console.layout= Org.apache.log4j.patternlayoutlog4j.appender.console.lAyout. conversionpattern= [%p]%d%c-%m%n############################################################################### ######## dailyrolling File \u6bcf\u5929\u4ea7\u751f\u4e00\u4e2a\u65e5\u5fd7\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\ u683c\u5f0f:log2009-09-11##################################################################################### #log4j. appender.file=org.apache.log4j.dailyrollingfileappenderlog4j.appender.file.datepattern= Yyyy-mm-ddlog4j.appender.file.file=log.loglog4j.appender.file.append=truelog4j.appender.file.threshold= errorlog4j.appender.file.layout=org.apache.log4j.patternlayoutlog4j.appender.file.layout.conversionpattern=%d{ Yyyy-m-d hh:mm:ss}%x[%5p] (%f:%l)%m%nlog4j.logger.com.opensymphony.xwork2=error
Importing the jar packages needed for spring development
Spring Transaction Management 1-------Environment building