2

これが私のサンプルクラスです:

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ウィーバーのバグですか?実際のビジネスには多くの具体的なサブクラスがあり、パターン「テンプレート」の標準実装であるため、どうすれば解決できますか。

4

2 に答える 2

0

問題を分析せず(私は通常SpringなしでAJを使用します)、時間があまりないので、AJユーザーのメーリングリストで質問することをお勧めします。そこにいる人たちは本当に有能で、おそらくそれがバグかどうかを知るでしょう。確かに1つである場合は、Bugzillaチケットを開きます。

于 2012-09-24T10:59:59.123 に答える
0

解決策が見つかりました:@targetはこの場合に適しています。

@withinと@targetの違いを説明するのに最適です。

私はなんてばかだ!

于 2012-09-25T11:58:55.827 に答える