2

我继承了一个使用 Spring AOP 的 webapps 代码库。Maven用于编译它,运行在Tomcat 6.x服务器上。我已经尝试通过 Eclipse 的“运行方式”运行项目,也可以mvn clean install在命令行上运行,然后更新 tomcatwebapps文件夹。两者都曾经给我同样的例外。

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.

我对 Spring AOP 很陌生,实际上是一般的 AOP。经过一些研究,当我通过 Eclipse 通过将项目转换为项目来运行服务器时,我能够解决这个问题AspectJ。这样做后,我不再收到这些错误。

这对我来说似乎很神奇。而且由于我在进行手动编译/部署时仍然面临同样的问题,我希望能够归零并解决这个问题。

这是我的片段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>

这是我的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 {
        //...
    }
    ...
}

这是我的片段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>

让我感到困惑的是,在我宣布我的项目是AspectJ自然之后发生了什么如此神奇的事情?那个日食停止了抱怨。

任何指针表示赞赏。

4

1 回答 1

1

我找到了解决方案。发生这种情况是因为我已经包装了<plugins>in<pluginManagement>标签。

在我删除它之后,我的 aspectj 插件开始正常工作,就像开始执行一样。有关此检查的详细信息,请查看此 stackoverflow 问题

于 2014-03-11T16:11:43.920 回答