1

I'm using Spring 3.0.5, and was wondering if it's possible, to somehow exclude aspect classes from being loaded that have been annotated with the @Aspect stereotype, but at the same time, include other aspect annotated classes? It seems to be an all or nothing if you're going the annotation route(which I am) I've tried looking at the and but can;t seem to find anything that hints at this.

The reason for this is that I have a central core library which contains aspects, but I may not want to include these aspects in every project I create using this central library.

Thanks.

4

1 回答 1

1

这个答案好久了。。。

如果您将 AspectJ 注释与 Spring AOP 一起使用,而不是 AspectJ 运行时或编译时编织,那么您很幸运。如果 @Aspect 注释的类也使用 @Component 之类的注释,Spring 只会选择它们。Spring 不认为 @Aspect 是组件扫描的候选对象。如果您使用 XML 配置,只需从配置中删除该 bean。

我建议不要使用会影响核心库的组件扫描。例如,如果您的应用程序是 com.example.myapp1,而您的核心库是 com.example.corelibrary.*,请确保您的组件扫描只查看 com.example.myapp1 而不是 com.example。

由于这个确切的原因,在应用程序的基本包之外进行组件扫描是不安全的。使用 bean 的 XML 配置拉入各个方面。

于 2011-12-06T19:12:53.333 回答