Detailed Explanation of spring Transaction Configuration in JSP

  • 2021-12-19 06:29:39
  • OfStack

Detailed Explanation of spring Transaction Configuration in JSP

A few days ago, I was asked how to prevent the server from going down and causing incomplete data operation.

Asked a colleague, it is a matter. Ah, it suddenly dawned on me that I was confused for 1 o'clock.

Declarative transaction configuration, which is the most recommended, is configured to service layer.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
  xmlns:xsi="" xmlns:aop=""
  <!--  Use annotation @Repository,@Service Automatic registration bean,  And guarantee that @Required , @Autowired The scope of the package in which the attributes of are injected  -->
  <context:component-scan base-package="com.rd,com.rongdu"/>

  <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&amp;characterEncoding=utf8"/>
    <property name="username" value="root"/>
    <property name="password" value="123456"/>

    <!--  Check the interval between idle connections in the database connection pool  -->
    <property name="idleConnectionTestPeriod" value="4" />
    <!--  Maximum lifetime of unused links in connection pool  -->
    <property name="idleMaxAge" value="240" />
    <!--  Set each partition to contain connection Maximum number  -->
    <property name="maxConnectionsPerPartition" value="20" />
    <!--  Set each partition to contain connection Minimum number  -->
    <property name="minConnectionsPerPartition" value="10" />
    <!--  Set the number of partitions per partition  -->
    <property name="partitionCount" value="3" />
    <!--  Set the in the partition connection Increased quantity  -->
    <property name="acquireIncrement" value="5" />
    <property name="statementsCacheSize" value="50"/>
     <property name="releaseHelperThreads" value="3"/>

  <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource">
      <ref bean="dataSource" />
  <bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
    <constructor-arg index="0" ref="dataSource"/> 

  <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
     <property name="dataSource" ref="dataSource"/>
  <tx:advice id="txAdvice" transaction-manager="txManager">
      <tx:method name="add*" propagation="REQUIRED" />
      <tx:method name="delete*" propagation="REQUIRED" />
      <tx:method name="update*" propagation="REQUIRED" />
      <tx:method name="*" propagation="REQUIRED" />

    <aop:pointcut id="allManagerMethod"
      expression="execution(* com.test.service.*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />

Among them, there is something wrong with a wildcard character. Transactions are used when updating data, and queries do not require transactions. So it's too violent to use * directly.

Thank you for reading, hope to help everyone, thank you for your support to this site!

Related articles: