これが私のサンプルクラスです:
public abstract class AbstractAgent {
public void count(List<Movie> movies) {
sum(movies);
}
protected abstract void sum(List<Movie> movies);
}
@Broker
public class DefaultAgent extends AbstractAgent {
@Override
protected void sum(List<Movie> movies) {
Validate.notNull(movies);
}
}
アスペクトの定義:
@Aspect
@Component
public class DaoObserver {
@Pointcut("@within(source.service.Broker)")
public void withinBroker() {
}
@AfterReturning("withinBroker()")
public void alertBroker(JoinPoint jp) {
System.out.println("Cached broker execution of {"
+ jp.getSignature().toShortString() + "}");
}
}
DefaultAgentのインスタンスがプロキシされていないことがわかりました。
以下のように行を試しました:
applicationContext.getBeansOfType(AbstractAgent.class);
'DefaultAgent $$ EnhancerByCGLIB $$ ae10cb14'のようなものを見つけることができると提案されましたが、それでも'DefaultAgent'です。
次に、クラス'DefaultAgent'に1つのパブリックメソッドを追加すると機能することがわかりました。
さらに掘り下げて、根本的な原因はアスペクトjウィーバーにあることがわかりました:
org.aspectj.weaver.patterns.WithinAnnotationPointcut.matchInternal(Shadow)
@Override
protected FuzzyBoolean matchInternal(Shadow shadow) {
ResolvedType enclosingType = shadow.getIWorld().resolve(shadow.getEnclosingType(), true);
if (enclosingType.isMissing()) {
shadow.getIWorld().getLint().cantFindType.signal(new String[] { WeaverMessages.format(
WeaverMessages.CANT_FIND_TYPE_WITHINPCD, shadow.getEnclosingType().getName()) }, shadow.getSourceLocation(),
new ISourceLocation[] { getSourceLocation() });
}
annotationTypePattern.resolve(shadow.getIWorld());
return annotationTypePattern.matches(enclosingType); **<--- AbstractAgent**
}
それはaspectjウィーバーのバグですか?実際のビジネスには多くの具体的なサブクラスがあり、パターン「テンプレート」の標準実装であるため、どうすれば解決できますか。