更新时间:2023-01-14 09:07:33
经过一些实验后,我似乎找到了自己的答案:
After some experiments I seem to have found the answer myself:
@EnableTransactionManagement
虽然它无论多么早它注册这个 internalTransactionAdvisor
@Transactional
注释。 @Import
声明中更改了上下文的顺序,因此 PersistenceConfig
包含 @EnableTransactionManagement
首先是 @EnableTransactionManagement
和 @EnableGlobalMethodSecurity
。全局方法安全性使用bean后处理,这似乎需要连接整个安全配置。 BeanPostProcessors是在上下文启动时尽早创建的,因此您不能在引导spring安全性所需的任何bean中使用声明性的 @Transactional
(在我的情况下 UserDetailsContextMapper
) - 尚未创建顾问!@EnableTransactionManagement
on each
piece of context configuration although it does matter how early this
annotation is discovered as it registers internalTransactionAdvisor
which actually processes @Transactional
annotations on created beans.@Import
declaration so
that PersistenceConfig
that holds @EnableTransactionManagement
is the
first. After this beans from other pieces can use AOP declarative
transaction.@EnableTransactionManagement
and @EnableGlobalMethodSecurity
. Global method security uses bean post processing which seems to require whole security configuration to be wired. BeanPostProcessors are created early on context start-up so you can't use declarative @Transactional
in any bean that would be needed to bootstrap spring security (in my case UserDetailsContextMapper
) - advisor is not yet created then!