【问题标题】:AspectJ not working after Transaction configuration in Spring Boot在 Spring Boot 中的事务配置后 AspectJ 不起作用
【发布时间】:2015-02-03 23:56:39
【问题描述】:

首先我遇到了事务无法正常工作的问题,因此我将配置从 @EnableTransactionManagement 更新为 @EnableTransactionManagement(proxyTargetClass=true),但更新后此错误在启动时抛出。

在注释了与 AspectJ 相关的所有代码后,错误消失了,事务运行正常,但我缺少我的 AspectJ 函数。

我尝试将@EnableTransactionManagement(proxyTargetClass=true) 替换为@EnableTransactionManagement(mode=AdviceMode.PROXY)@EnableTransactionManagement @EnableLoadTimeWeaving,它们都没有让我使用AspectJ,使用调试器我可以看到建议根本没有执行。

AppConfig.java

@EnableAutoConfiguration
@ComponentScan(basePackages = { "com.geopro" })
@EnableJpaRepositories(basePackages = { "com.geopro.repositories" })
@EntityScan(basePackages = { "com.geopro.entities" })
@EnableTransactionManagement(proxyTargetClass=true)//(mode=AdviceMode.ASPECTJ)//
public class AppConfig {
    @Bean
    public HibernateJpaSessionFactoryBean sessionFactory(EntityManagerFactory emf) {
         HibernateJpaSessionFactoryBean factory = new HibernateJpaSessionFactoryBean();
         factory.setEntityManagerFactory(emf);
         return factory;
    }
}

【问题讨论】:

  • 使用 mode=ASPECTJ 时,您需要使用编译或前置时间编织来编织您的方面。因此,仅启用 aspectj 比您现在拥有的要困难一些。
  • 现在我正在使用(proxyTargetClass=true),我正在寻找 AOP 和事务。

标签: spring spring-boot aspectj spring-transactions


【解决方案1】:

故事的寓意是永远不要在同一个类中混合 Transactions 和 AspectJ 函数,我了解到,Transaction 在其内部使用 AOP,其 AOP 不能很好地与用户 AOP。

【讨论】:

    猜你喜欢
    • 2016-03-21
    • 1970-01-01
    • 2015-09-01
    • 2018-09-10
    • 1970-01-01
    • 1970-01-01
    • 2021-08-30
    • 2017-10-08
    • 1970-01-01
    相关资源
    最近更新 更多