在两个Web应用程序之间共享Spring切面类
我的应用程序由两个 Web 应用程序和 EAR 级别的 jar 文件组成。 一个 Web 应用程序(比方说 SPApp)是使用 Spring 构建的,另一个 Web 应用程序是使用 Struts (STApp) 构建的。 我想分享此处定义的 SPApp 的 Aspect 类 SystemArchitecture
Spring aop
6.2.3.3。共享通用切入点定义
。
我已在 EAR 级别 jar 文件中添加了 SystemArchitecture 类,并从 SPApp 调用,但在访问 STApp 时不会执行。
然后我将方面类 SystemArchitecture
移到 STApp 中,令人惊讶的是它起作用了。 当我将 SystemArchitecture
放入 EAR 级别库时,我不确定出了什么问题。
请帮忙。
谢谢, 哈努曼特
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 class 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Spring AOP 在 Spring 之外无法工作。 AOP 的 Spring 实现基于动态代理,其中 Spring bean 工厂将代理建议的类来注入切入点。您所追求的是所谓的“加载时编织”,其中使用 java 代理来拦截 ClassLoader 并在加载建议的类时对其进行装饰。这是 AspectJ 功能,而不是 Spring AOP。在这里阅读更多内容: http://www.eclipse.org/aspectj/doc /released/devguide/ltw.html
Spring 和 AspectJ 也可以一起使用,但仅限于 spring 驱动的应用程序:http://static.springsource.org /spring/docs/3.0.0.RC2/spring-framework-reference/html/ch07s08.html
不过,如果你想要“真正的”AOP,独立于Spring,那么你需要进行加载时编织和 AspectJ。
编辑:可能误读了你的问题。您说只有当您将建议类放入应用程序本身时,它才在您的 struts 应用程序中起作用。从那里我了解到您的 Struts 应用程序也是 Spring 驱动的。在不知道您的配置的情况下很难给出答案。具体来说,web.xml(两者)、application.xml 和您的 spring 配置。
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.