Reputation: 5963
I have inherited a webapps codebase that makes use of Spring AOP. Maven is used to compile it, run on Tomcat 6.x server. I have tried running the project via Eclipse's "Run As" & also by running mvn clean install
on command line & then updating the tomcat webapps
folder. Both used to give me the same exception.
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.xyz.ABCAspect#0' defined in ServletContext resource [/WEB-INF/rest-servlet.xml]: No matching factory method found: factory method 'aspectOf()'. Check that a method with the specified name exists and that it is static.
I am pretty new to Spring AOP, actually AOP in general. After some research I was able to fix this issue when I ran the server through Eclipse by converting the project in to AspectJ
project. After doing this I stopped getting these errors.
This seems very magical to me. And since I am facing the same issue still when doing manual compile/deploy I want to be able to zero down & fix this issue.
Here is snippet of my WEB-INF/rest-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<aop:aspectj-autoproxy/>
<bean class="com.xyz.rest.aop.ABCAspect" factory-method="aspectOf">
<property name="converter" ref="defaultConverter"/>
</bean>
Here is my ABCAspect
:
@Aspect
public class ABCAspect {
private Converter converter;
@Around("execution(@com.xyz.converter.DTOType * *(..)) && @annotation(dtoType)")
public Object convertType(ProceedingJoinPoint pjp, DTOType dtoType) throws Throwable {
//...
}
...
}
Here is snippet of my pom.xml
:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal> <!-- use this goal to weave all your main classes -->
<goal>test-compile</goal> <!-- use this goal to weave all your test classes -->
</goals>
</execution>
</executions>
<configuration>
<source>1.6</source>
<target>1.6</target>
<outxml>true</outxml>
<showWeaveInfo>false</showWeaveInfo>
<Xlint>warning</Xlint>
<verbose>true</verbose>
</configuration>
</plugin>
The thing that confounds me is, what was so magical that happened after I declared my project to be AspectJ
nature? that eclipse stopeed complaining.
Any pointers appreciated.
Upvotes: 2
Views: 3994
Reputation: 5963
I found the solution. This was happening because I had wrapped the <plugins>
in <pluginManagement>
tag.
After I removed it, my aspectj plugin started working proeprly as in started to excecute. For detailed information on this check this stackoverflow question.
Upvotes: 1