Question

Here are my sample classes:

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 definition:

@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() + "}");
    }
}

I found the instance of DefaultAgent was not proxied!

Tried the line as below:

applicationContext.getBeansOfType(AbstractAgent.class);

Proposed I could find something like 'DefaultAgent$$EnhancerByCGLIB$$ae10cb14', but still 'DefaultAgent'.

Then I found it will work if I add one public method to class 'DefaultAgent'.

Dig further I found the root cause is in aspectj weaver:

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**
}

Is it a bug of aspectj weaver? How can I solve it since I have many concrete sub-classes in real biz and it's a standard implementation of pattern 'Template'.

Was it helpful?

Solution

Without having analysed the problem (I use AJ without Spring usually) and not having much time, I suggest you ask your question on the AJ users mailing list. The guys there are really competent and will probably find out if it is a bug. If you are pretty sure it is one, open a Bugzilla ticket.

OTHER TIPS

Found the solution: @target is suitable for this case.

It's perfect to describe the difference between @within and @target.

How fool I am!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top