开发者

sharing spring aspect class between two webapplications

I have application consisting two web apps and EAR level jar files. One web app (Lets say SPApp) is built using Spring and another using Struts (STApp). I want to share the Aspect class SystemArchitecture of SPApp as defined here spring aop

6.2.3.3. Sharing common pointcut definitions

in STApp.

I have added SystemArchitecture class in EAR level jar file and gets invoked from SPApp but doesn't execute when STApp is accessed.

So then I moved the aspect 开发者_如何学JAVAclass SystemArchitecture inside STApp and surprisingly it worked. I am not sure what is going wrong when I place SystemArchitecture in EAR level lib.

Please help.

Thanks, Hanumant


Spring AOP will not work outside spring. The Spring implementation of AOP is based on dynamic proxying where the spring bean factory will proxy advised classes to inject your pointcuts. What you are after is what's called "load time weaving" in where a java agent is used to intercept the ClassLoader and decorate advised classes when they are loaded. This is an AspectJ functionality, not a Spring AOP. Read more here: http://www.eclipse.org/aspectj/doc/released/devguide/ltw.html

Spring and AspectJ can play together as well, but it's limited to spring driven applications: http://static.springsource.org/spring/docs/3.0.0.RC2/spring-framework-reference/html/ch07s08.html

Still, if you want "true" AOP, independant of Spring then you need to go load-time weaving and AspectJ.

EDIT: may have misread your question. You say it works in your struts app only when you put your advise class in the app itself. From that I read that your Struts app is Spring driven as well. It's hard to give an answer without knowing your config. Specifically, web.xml (both), application.xml and your spring configs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜