春天没有在@AspectJ类中注入bean

我正在努力将bean注入@AspectJ类中。

我有一个AspectJ,它将一个运行良好的类编织到jdbc中。目的是拦截并重写一些prepare语句。

@AspectJ AroundJdbc{

//store is actually an openJPA entityManager wrapper
@Autowired
Store  store;

@Autowired
PlatformTransactionmanager transactionmanager;


@Around("execution(java.sql.PreparedStatement org.postgresql.jdbc.PgConnection.prepareStatement(String,int,int))")
public PreparedStatement rewrite(ProceedingJoinPoint joinPoint) {
//...
}

这部分效果很好!

现在,我想将2个bean注入到AroundJdbc类中,以便使用将在重写方法中使用的一些外部数据对其进行初始化。

为此,我阅读了所有文档和stackoverflow问题。

我在@Aspect类中添加了@Configurable,在mu config类上激活了@EnableLoadTimeWeaving和@ EnableSpringConfigured,spring-instrument在类路径中。

我什至必须添加特定的代码来强制激活Beanconfigurer,如此处指定的:https://github.com/spring-projects/spring-framework/issues/13658#issuecomment-453364781

结果是,尽管由AspectJ正确编织了该类,但store和transactionmanager始终为null。当我调试测试时,我看到了这一点,代码在建议中正确停止,但是store始终为null。我知道这些bean已正确实例化,因为它们也被注入到主测试类中以运行测试。

另一方面,如果我尝试将AroundJdbc初始化为像这样的ConfigurationClass中的单例:

@Scope(value = "singleton")
    @Bean(initMethod = "aspectOf")
    public AroundJdbc aroundJdbc() {
        return Aspects.aspectOf(AroundJdbc.class);
    }

我无法设置应用程序上下文,因为在AroundJdbc类中找不到AspectOf方法,这意味着未执行LTW编织。

因此,任何提示将不胜感激。

我想念什么?

yuanxiao_001 回答:春天没有在@AspectJ类中注入bean

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2878142.html

大家都在问