Reputation: 674
Implemented AOP using AspectJ without Spring. It works perfectly fine when running in Eclipse (Tomcat server) but not when run directly in Tomcat. Have added required dependencies in the pom but of no use. Not able to figure out the issue.
Aspect class:
@Aspect
public class FeatureAOP {
private static final Logger LOG = LoggerFactory.getLogger(FeatureAOP.class);
@Pointcut("execution(* x.y.z.rest.ModifiersFacadeWrapper.*(..)) && !execution(* x.y.z.rest.ModifiersFacadeWrapper.getUriInfo(..))")
protected void pointCut() {
}
@Before("x.y.z.rest.aop.FeatureAOP.pointCut() && this(mf) ")
public void parseParams(JoinPoint jp, ModifiersFacadeWrapper mf) {
LOG.info("Entered JoinPoint: {}", jp.getSignature());
String feature = mf.getUriInfo().getPathParameters().get("feature").get(0);
Feature featureEnum = Feature.get(feature);
mf.setFeature(featureEnum);
LOG.info("Feature set: {}", mf.getFeature());
}
}
aop.xml:
<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<weaver options="-verbose -showWeaveInfo -Xset:weaveJavaxPackages=true -debug">
<include within="x.y.z"/>
</weaver>
<aspects>
<aspect id="featureAspect" class="x.y.z.rest.aop.FeatureAOP" ></aspect>
</aspects>
</aspectj>
Read in a few post to set javaagent in Tomcat to aspectjweaver lib. That also didn't help.
export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/home/sumit/Downloads/apache-tomcat-8.0.17/webapps/dpi-manager/WEB-INF/lib/aspectjweaver-1.8.5.jar"
Upvotes: 0
Views: 988
Reputation: 674
Found solution to this using maven. One needs to add aspectj-maven-plugin in pom.xml.
< plugin >
< groupId > org.codehaus.mojo < /groupId>
<artifactId>aspectj-maven-plugin</artifactId >
< version > 1.4 < /version>
<configuration>
<source>1.7</source >
<target > 1.7 < /target>
</configuration >
<executions >
<execution >
<goals>
<goal>compile</goal >
< /goals>
</execution >
< /executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId >
< artifactId > aspectjrt < /artifactId>
<version>${aspectj.version}</version >
< /dependency>
<dependency>
<groupId>org.aspectj</groupId >
< artifactId > aspectjtools < /artifactId>
<version>${aspectj.version}</version >
< /dependency>
</dependencies >
< /plugin>
Example: https://github.com/mscharhag/blog-examples/blob/master/exception-translation/pom.xml
Upvotes: 1