Spring 事务不起作用(二)
当使用 spring root 和 mvc 时, mvc 一定要分开扫描组件,如果通过mvc 扫描所有组件会导致事务不起作用
一般 servlet 只扫描 web 的 组件,比如 Controller 等
其他组件如 Service 需要由 root 扫描
或者只使用 servlet
@EnableTransactionManagement
and <tx:annotation-driven/>
only looks for @Transactional
on beans in the same application context they are defined in.
This means that,
if you put annotation driven configuration in a WebApplicationContext
for a DispatcherServlet
,
it only checks for @Transactional
beans in your controllers,
and not your services.
See Section 22.2, “The DispatcherServlet” for more information.