本文介绍了Spring factory-method=“aspectOf"当我们从 RAD 部署应用程序时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用具有 Spring 支持的 AspectJ.我在 ApplicationContext.xml 中声明了我的方面,如下所示.

We are using AspectJ with Spring support. I have declared my aspect in my ApplicationContext.xml as below.

<context:annotation-config />
<context:spring-configured />
<context:component-scan base-package="com,com.util">
    <context:exclude-filter type="regex" expression="com.xyz*.*" />
</context:component-scan>
<bean id="xyz" class="com.util.XyzAspect" factory-method="aspectOf"/>

方面类:

@Configurable
@Aspect
public class XyzAspect {

 @Autowired
 private XyzUtil xyzUtil;

 @After("showPoint() ")
 public void logUser( JoinPoint pjp ) throws Throwable {
   Sysout("Some log Statement");
 }
}

当我从命令提示符执行 Maven 构建并在 Websphere 应用程序服务器 (7.0) 中手动部署 EAR 时,它工作正常.但是当我从 RAD7.5(Rational Application Developer)管理控制台进行部署时,它给出了'找不到匹配的工厂方法:工厂方法'aspectOf''问题.

It is working fine, when I am doing the Maven build from command prompt and deploy the EAR manually in the Websphere Application server (7.0). but when I am doing the deployment from RAD7.5(Rational Application Developer) admin console, it is giving 'No matching factory method found: factory method 'aspectOf'' issue.

有人可以完全解决这个问题吗?我也想从 RAD 运行应用程序.提前致谢.

Can someone do the need full to get out of this issue. I want to run the application from RAD also. Thanks in advance.

推荐答案

aspectOf 方法由 AspectJ 编织到您的 XyzAspect 中.我相信您使用编译时编织,因此 Maven 生成的 EAR 已正确修补"类 XyzAspect 的字节码,因此它部署正常.如果您使用 IDE 组装项目,则类的字节码会丢失某些内容(它是 Java 源代码的精确表示,并且是不完整的").在编织 AspectJ 期间,将您的方面转换"为单例,即添加静态变量以保存唯一实例和方法 (aspectOf) 以获取唯一实例.看看这个线程获取更多信息.

The method aspectOf is weaved into your XyzAspect by AspectJ. I believe you use compile-time weaving, so EAR produced by Maven has correctly "patched" bytecode for class XyzAspect thus it deploys OK. If you assemble project with IDE, the bytecode of the class is missing certain things (it is exact representation of Java source an is "incomplete"). During the weaving AspectJ "converts" your aspect into singleton, that is adds static variable to hold the only instance and a method (aspectOf) to get that only instance. Have a look at this thread to get more information.

这篇关于Spring factory-method=“aspectOf"当我们从 RAD 部署应用程序时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 16:40