AspectJ load time weaving not working on Spring beans

天大地大妈咪最大 提交于 2019-12-04 04:20:29

The problem was the return type - if I do:

@Bean
Object annotatedClass1() {
    return new AnnotatedClass1(new AnnotatedClass2());
} 

the weaving starts to work for the bean as well. My initial assumption was that it has something to do with Spring caching the bean and not using the weaved version, but this didn’t make sense because:

  • load time weaving is supposed to act at, well… class load time :). Then, it doesn’t matter what the method returns, the class should have the aspects.
  • I’ve actually checked the debug output for both Spring and AspectJ and no mention of my class so it must have been ignored somehow.

This is the first time I’ve used this stuff, so I might be misunderstanding things. If anyone can explain why the return type of the @Bean method has anything to do with weaving I’d be happy to accept your answer instead of this one.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!