问题
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"/>
Aspect Class:
@Configurable
@Aspect
public class XyzAspect {
@Autowired
private XyzUtil xyzUtil;
@After("showPoint() ")
public void logUser( JoinPoint pjp ) throws Throwable {
Sysout("Some log Statement");
}
}
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.
Can someone do the need full to get out of this issue. I want to run the application from RAD also. Thanks in advance.
回答1:
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.
来源:https://stackoverflow.com/questions/29012515/spring-factory-method-aspectof-is-not-working-when-we-deploy-the-application-f