java - Why Spring AOP is not weaving external jars at runtime? -


i have java application build upon spring 3. project has jar dependency.

this dependency contains @org.aspectj.lang.annotation.aspect class (lets say, com.aspectprovider.aspects.myaspect). there's @before advice weave method classes implements interface foo. like:

@before("execution(* com.project.foo.save(..))") 

the foo interface can inside "project" or in jar. doesn't matter example.

my project contains classes implements foo. classes want weaved, of course.

my spring application context configuration file (applicationcontext.xml) contains line:

<aop:aspectj-autoproxy /> 

i declare aspect bean, , inject properties:

<bean id="myaspect" class="com.aspectprovider.aspects.myaspect"   factory-method="aspectof" >   <property name="someproperty" value="somevalue" /> </bean> 

trough logging can see myaspect instantiated , properties injected. method save not intercepted. problem.

if copy aspect classes jar application has spring, works. when aspects contained in external jars, method save not intercepted. clues?

edit: how calling foo's save method:

//in jsf managed bean @inject private foo myfoo;  //there's implementation of foo in package spring looking at. injected correctly.  public string someaction() {     myfoo.save("something"); //the @before advice called if class containing aspect not in external jar }   //in class main method void main(string[] ars) {     applicationcontext ac = new classpathxmlapplicationcontext("applicationcontext.xml");     //right after previous line, can see in log myaspect instantiated.     foo myfoo = ac.getbean(foo.class);     myfoo.save("something"); //the @before advice called if class containing aspect not in external jar } 

basically, applicationcontext.xml has following lines:

<context:annotation-config /> <context:component-scan base-package="com.project" /> <context:component-scan base-package="com.aspectprovider.aspects" /> <aop:aspectj-autoproxy /> <bean id="myaspect" class="com.aspectprovider.aspects.myaspect" factory-method="aspectof" >     <property name="someproperty" value="somevalue" /> </bean> 

i don't think need put like

<context:component-scan  base-package="com.project">     <context:include-filter type="aspectj" expression="com.aspectprovider.aspects.*" /> </context:component-scan> 

i have same problem. solved problem packaging maven. check aspectj-maven-plugin , option weavedependency

http://mojo.codehaus.org/aspectj-maven-plugin/weavejars.html


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -