Reputation: 4192
My Aspect is as follows:
@Aspect
public class SomeAspect{
//define pointcuts
// define Advices pertaining to pointcuts
}
My aspect-config xml file:
<?xml ...?>
<beans ...
xmlns:aop
xmlns:context ..>
<bean id="someAspect" class="...SomeAspect"/>
<aop:aspectj-autoproxy />
</beans>
This runs perfectly fine
What I require:
I want to get rid of writing bean definition for each Aspect as shown above in my config xml file.
I tried the following:
Added @Component
on SomeAspect
and in xml added <context-component-scan>
with respective package containing my Aspect hoping that my class gets picked up as a Bean and as an Aspect.
However, my Aspect was not getting picked up at all.
Any pointers?
Upvotes: 5
Views: 663
Reputation: 42834
The context:component-scan
element has a sub-element which you can use to include annotation classes to use to be picked up by the scan.
Take a look at the context:include-filter
element, and its attributes.
<context:component-scan base-package="my.package.to.scan">
<context:include-filter type="annotation" expression="org.aspectj.lang.annotation.Aspect"/>
</context:component-scan>
I would think what you tried would have work, but without seeing it exactly as you did it, it is hard to say for sure.
Upvotes: 4