Spring transaction configuration in JSP, and jspspring transaction details
Spring transaction configuration in JSP
A few days ago, I was asked how to prevent server downtime, resulting in incomplete data operations.
I asked my colleague about the transaction. Ah, suddenly realized, confused for a moment.
Declarative transaction configuration, which is the most recommended, is configured to the service layer.
<? Xml version = "1.0" encoding = "UTF-8"?> <Beans xmlns =" http://www.springframework.org/schema/beans "Xmlns: context =" http://www.springframework.org/schema/context "Xmlns: xsi =" http://www.w3.org/2001/XMLSchema-instance "Xmlns: aop =" http://www.springframework.org/schema/aop "Xmlns: tx =" http://www.springframework.org/schema/tx "Xsi: schemaLocation =" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans Spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx Spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context Spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop /Spring-aop-2.0.xsd "> <! -- Use annotation @ Repository and @ Service to automatically register the bean and ensure that the @ Required and @ Autowired attributes are injected with the package range --> <context: component-scan base-package = "com. rd, com. rongdu "/> <context: annotation-config/> <bean id =" dataSource "class =" com. jolbox. bonecp. boneCPDataSource "destroy-method =" close "> <! -- Connection Info --> <property name = "driverClass" value = "com. mysql. jdbc. driver "/> <property name =" jdbcUrl "value =" jdbc: mysql: // localhost: 3306/sfd? UseUnicode = true & characterEncoding = utf8 "/> <property name =" username "value =" root "/> <property name =" password "value =" 123456 "/> <! -- Check the idle connection interval in the database connection pool --> <property name = "idleConnectionTestPeriod" value = "4"/> <! -- Maximum lifetime of unused connections in the connection pool --> <property name = "idleMaxAge" value = "240"/> <! -- Set the maximum number of connections in each partition --> <property name = "maxConnectionsPerPartition" value = "20"/> <! -- Set the minimum number of connections in each partition --> <property name = "minConnectionsPerPartition" value = "10"/> <! -- Set the number of partitions --> <property name = "partitionCount" value = "3"/> <! -- Set the number of connections in the partition --> <property name = "acquireIncrement" value = "5"/> <property name = "statementsCacheSize" value = "50"/> <property name = "releaseHelperThreads" value = "3"/> </bean> <bean id = "jdbcTemplate" class = "org. springframework. jdbc. core. jdbcTemplate "> <property name =" dataSource "> <ref bean =" dataSource "/> </property> </bean> <bean id =" namedParameterJdbcTemplate "class =" org. springframework. jdbc. core. namedparam. namedParameterJdbcTemplate "> <constructor-arg index =" 0 "ref =" dataSource "/> </bean> <bean id =" txManager "class =" org. springframework. jdbc. datasource. dataSourceTransactionManager "> <property name =" dataSource "ref =" dataSource "/> </bean> <tx: advice id = "txAdvice" transaction-manager = "txManager"> <tx: attributes> <tx: method name = "add *" propagation = "REQUIRED"/> <tx: method name = "delete *" propagation = "REQUIRED"/> <tx: method name = "update *" propagation = "REQUIRED"/> <tx: method name = "*" propagation = "REQUIRED"/> </tx: attributes> </tx: advice> <aop: config> <aop: pointcut id = "allManagerMethod" expression = "execution (* com. test. service. *. *(..)) "/> <aop: advisor advice-ref =" txAdvice "pointcut-ref =" allManagerMethod "/> </aop: config> </beans>
Here, a wildcard is a problem. Transactions are used to update data, and transactions are not required for queries. Therefore, it is too violent to use * directly.
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!