Spring mvc 配置事务的注意点

1.applicationContext.xml中,去掉对controller的扫描

  <context:component-scan base-package="com.trans">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>


2.**-servlet.xml 中,去掉对 service的扫描,加入对controller的扫描

  <context:component-scan base-package="com.trans">
  <context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Service" />
</context:component-scan>


3.事务的配置只有在 applicationContext.xml中才会起作用,即

<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

必须配置在 applicationContext.xml 中


4.用事务去控制的service,不能加try catch去捕获异常,否则不能被spring拦截到,事务就失效了。


猜你喜欢

转载自blog.csdn.net/zxcvqwer19900720/article/details/20999623