AOP を既存の (大きな) Spring プロジェクトに使用しようとしています。問題は、主にパフォーマンスのためだけでなく、変更できない最終クラスがあるため、Spring が ApplicationContext 内のすべてのオブジェクトのプロキシを作成することを望まないことです。
次の側面を定義することにより、Spring 検索を「com.foo.bar.*」内のみにしようとしました。
com.baz.MyAspect
@Aspect
public class MyAspect {
private static final Logger LOGGER = LoggerFactory.getLogger(MyAspect.class);
@Before("within(com.foo.bar.*) && " +
"execution(* com.foo.bar.MyController.handleRequest(..))")
public void getData() {
// Nothing yet
}
}
そして、次の行を構成に追加しました。
<?xml version="1.0" encoding="utf-8"?>
<beans ...>
<aop:aspectj-autoproxy proxy-target-class="true" />
<bean id="myAspect" class="com.baz.MyAspect"/>
</beans>
しかし、アプリを実行すると、次の例外が発生します。
Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.foobar.FinalController]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class com.foobar.FinalController
そのため、Spring は within 式で定義されたパッケージ以外のパッケージをスキャンしているようです。スキャンするパッケージを指定する方法や、この問題を解決する他の方法があるかどうかを知りたいです。