问题描述:

I'm trying to solve the following problem: I have an aspect defined like this:

public aspect ComponentAspect {

declare @type : uk.co.xxx.* : @Component;

}

As expected it annotates everything in "uk.co.xxx" package, the thing is I don't need to annotate all classes in this package, only those matching certain pattern, for example I have classes ending with ...Client.java and only these I want to annotate. So I would expect code like this:

public aspect ComponentAspect {

declare @type : uk.co.xxx.workflow.*Client : @Component;

}

but of cause it is only my wishful thinking.

Any ideas how I can achieve my result?

Thanks a lot for any idea, so far I spent 2 hours without progress at all :(

网友答案:

Why wishful thinking? It works as you expect. You just need to be careful which packages and/or subpackages you are targetting with your type pattern.

Maybe what you really want to do is target all classes with a certain name within all subpackages of a certain package. In this case you need the .. syntax, like so:

public aspect ComponentAspect {
    declare @type : uk.co.xxx.workflow..*Client : @Component;
}

I tried in one of my applications, it works like a charm.

相关阅读:
Top