Spring Boot是否会自动在控制器层添加@Transactional注解?我尝试将@Transactional放在服务层,但似乎控制器层会覆盖该注解。
我有以下配置:
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="find*" read-only="true" isolation="READ_COMMITTED"
propagation="NOT_SUPPORTED" />
<tx:method name="load*" read-only="true" isolation="READ_COMMITTED"
propagation="NOT_SUPPORTED" />
<tx:method name="get*" read-only="true" isolation="READ_COMMITTED"
propagation="NOT_SUPPORTED" />
<tx:method name="*" timeout="30" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:advisor advice-ref="txAdvice"
pointcut="execution(* *..service.*Service*.*(..))" order="1" />
</aop:config>
即使我删除了该配置,交易仍然有效。
编辑:
这是我的数据源配置。
<bean id="msDataSource" class="org.apache.tomcat.jdbc.pool.DataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.main.driverClass}" />
<property name="url" value="${jdbc.main.url}" />
<property name="username" value="${jdbc.main.username}" />
<property name="password" value="${jdbc.main.password}" />
</bean>
<bean id="msPUM"
class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="defaultDataSource" ref="msDataSource" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="msPUM" />
<!--<property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="ORACLE"/> <property name="generateDdl" value="false"/>
<property name="showSql" value="true" /> </bean> </property> -->
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>