eclipse - spectj-maven-plugin 的编译目标出现奇怪的问题

标签 eclipse maven aspectj spring-roo aspectj-maven-plugin

我有一个 spring roo 项目,可以在 sts/eclipse 下构建和运行。但是,当我运行 maven [mvn package] 时,我系统地收到以下错误:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building bignibou 0.1.0.BUILD-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- apt-maven-plugin:1.0.6:process (default) @ bignibou ---
[INFO] 
[INFO] --- aspectj-maven-plugin:1.2:compile (default) @ bignibou ---
[ERROR] The method addListener(ContextLoaderListener) is undefined for the type ServletContext
[ERROR] The method addListener(RequestContextListener) is undefined for the type ServletContext
[ERROR] The method addListener(HttpSessionEventPublisher) is undefined for the type ServletContext
[ERROR] The method setInitParameter(String, String) is undefined for the type ServletContext
[ERROR] The method addFilter(String, CharacterEncodingFilter) is undefined for the type ServletContext
[ERROR] The method addFilter(String, HiddenHttpMethodFilter) is undefined for the type ServletContext
[ERROR] The method addFilter(String, OpenEntityManagerInViewFilter) is undefined for the type ServletContext
[ERROR] The method addFilter(String, DelegatingFilterProxy) is undefined for the type ServletContext
[ERROR] The method addServlet(String, DispatcherServlet) is undefined for the type ServletContext
[WARNING] advice defined in com.bignibou.aop.AdvertisementExistsAndBelongsToMemberCheckAspect has not been applied [Xlint:adviceDidNotMatch]
[WARNING] advice defined in com.bignibou.aop.CurriculumExistsAndBelongsToMemberCheckAspect has not been applied [Xlint:adviceDidNotMatch]
[WARNING] advice defined in com.bignibou.aop.AdvertisementExistsAndBelongsToMemberCheckAspect has not been applied [Xlint:adviceDidNotMatch]
[WARNING] advice defined in com.bignibou.aop.CurriculumExistsAndBelongsToMemberCheckAspect has not been applied [Xlint:adviceDidNotMatch]
[WARNING] advice defined in com.bignibou.aop.AdvertisementExistsCheckAspect has not been applied [Xlint:adviceDidNotMatch]
[WARNING] advice defined in com.bignibou.aop.TestCheckAspect has not been applied [Xlint:adviceDidNotMatch]
[WARNING] advice defined in org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl has not been applied [Xlint:adviceDidNotMatch]
[WARNING] advice defined in org.springframework.mock.staticmock.AbstractMethodMockingControl has not been applied [Xlint:adviceDidNotMatch]
[WARNING] advice defined in org.springframework.mock.staticmock.AbstractMethodMockingControl has not been applied [Xlint:adviceDidNotMatch]
[WARNING] advice defined in org.springframework.scheduling.aspectj.AbstractAsyncExecutionAspect has not been applied [Xlint:adviceDidNotMatch]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.027s
[INFO] Finished at: Wed Nov 20 19:02:07 CET 2013
[INFO] Final Memory: 32M/620M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.2:compile (default) on project bignibou: Compiler errors :
[ERROR] error at servletContext.addListener(new ContextLoaderListener(rootContext));
[ERROR] ^^^^^^^^
[ERROR] /home/julien/Documents/projects/site-garde-enfants/bignibou/src/main/java/com/bignibou/configuration/web/WebAppInitializer.java:29:0::0 The method addListener(ContextLoaderListener) is undefined for the type ServletContext
[ERROR] error at servletContext.addListener(new RequestContextListener());
[ERROR] ^^^^^^^^
[ERROR] /home/julien/Documents/projects/site-garde-enfants/bignibou/src/main/java/com/bignibou/configuration/web/WebAppInitializer.java:30:0::0 The method addListener(RequestContextListener) is undefined for the type ServletContext
[ERROR] error at servletContext.addListener(new HttpSessionEventPublisher());
[ERROR] ^^^^^^^^
[ERROR] /home/julien/Documents/projects/site-garde-enfants/bignibou/src/main/java/com/bignibou/configuration/web/WebAppInitializer.java:31:0::0 The method addListener(HttpSessionEventPublisher) is undefined for the type ServletContext
[ERROR] error at servletContext.setInitParameter("defaultHtmlEscape", "true");
[ERROR] ^^^^^^^^^^^^^
[ERROR] /home/julien/Documents/projects/site-garde-enfants/bignibou/src/main/java/com/bignibou/configuration/web/WebAppInitializer.java:33:0::0 The method setInitParameter(String, String) is undefined for the type ServletContext
[ERROR] error at fr = servletContext.addFilter("encodingFilter", new CharacterEncodingFilter());
[ERROR] ^^^^^^
[ERROR] /home/julien/Documents/projects/site-garde-enfants/bignibou/src/main/java/com/bignibou/configuration/web/WebAppInitializer.java:37:0::0 The method addFilter(String, CharacterEncodingFilter) is undefined for the type ServletContext
[ERROR] error at fr = servletContext.addFilter("hiddenHttpMethodFilter", new HiddenHttpMethodFilter());
[ERROR] ^^^^^^
[ERROR] /home/julien/Documents/projects/site-garde-enfants/bignibou/src/main/java/com/bignibou/configuration/web/WebAppInitializer.java:43:0::0 The method addFilter(String, HiddenHttpMethodFilter) is undefined for the type ServletContext
[ERROR] error at fr = servletContext.addFilter("Spring OpenEntityManagerInViewFilter", new OpenEntityManagerInViewFilter());
[ERROR] ^^^^^^
[ERROR] /home/julien/Documents/projects/site-garde-enfants/bignibou/src/main/java/com/bignibou/configuration/web/WebAppInitializer.java:47:0::0 The method addFilter(String, OpenEntityManagerInViewFilter) is undefined for the type ServletContext
[ERROR] error at fr = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());
[ERROR] ^^^^^^
[ERROR] /home/julien/Documents/projects/site-garde-enfants/bignibou/src/main/java/com/bignibou/configuration/web/WebAppInitializer.java:51:0::0 The method addFilter(String, DelegatingFilterProxy) is undefined for the type ServletContext
[ERROR] error at ServletRegistration.Dynamic dispatcher = servletContext.addServlet("bignibou", new DispatcherServlet(mvcContext));
[ERROR] ^^^^^^^
[ERROR] /home/julien/Documents/projects/site-garde-enfants/bignibou/src/main/java/com/bignibou/configuration/web/WebAppInitializer.java:58:0::0 The method addServlet(String, DispatcherServlet) is undefined for the type ServletContext
[ERROR] -> [Help 1]

这是我的WebApplicationInitializer类:

public class WebAppInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(BaseConfiguration.class);

        servletContext.addListener(new ContextLoaderListener(rootContext));
        servletContext.addListener(new RequestContextListener());
        servletContext.addListener(new HttpSessionEventPublisher());

        servletContext.setInitParameter("defaultHtmlEscape", "true");

        FilterRegistration.Dynamic fr;

        fr = servletContext.addFilter("encodingFilter", new CharacterEncodingFilter());
        fr.setAsyncSupported(Boolean.TRUE);
        fr.setInitParameter("encoding", "UTF-8");
        fr.setInitParameter("forceEncoding", "true");
        fr.addMappingForUrlPatterns(null, true, "/*");

        fr = servletContext.addFilter("hiddenHttpMethodFilter", new HiddenHttpMethodFilter());
        fr.setAsyncSupported(Boolean.TRUE);
        fr.addMappingForUrlPatterns(null, true, "/*");

        fr = servletContext.addFilter("Spring OpenEntityManagerInViewFilter", new OpenEntityManagerInViewFilter());
        fr.setAsyncSupported(Boolean.TRUE);
        fr.addMappingForUrlPatterns(null, true, "/*");

        fr = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());
        fr.setAsyncSupported(Boolean.TRUE);
        fr.addMappingForUrlPatterns(null, true, "/*");

        AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
        mvcContext.register(WebMvcConfig.class);

        ServletRegistration.Dynamic dispatcher = servletContext.addServlet("bignibou", new DispatcherServlet(mvcContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");

    }
}

有人可以帮忙吗?

最佳答案

事实证明,这是 Maven 依赖项的另一个问题,即 jSTL impl

通过排除错误版本的 servlet api 传递依赖项,编译错误就消失了。

见下文:

<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
<exclusions>
    <exclusion>
    <artifactId>servlet-api</artifactId>
    <groupId>javax.servlet</groupId>
    </exclusion>
</exclusions>
</dependency>

关于eclipse - spectj-maven-plugin 的编译目标出现奇怪的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20103567/

相关文章:

android - 这个android布局xml block 中的错误是什么

eclipse - 如何在不同的计算机上使用eclipse工作空间

java - 如何在 Java 项目中使用 HeidelTime 时间标记器?

java - 构造函数调用不同类的 AspectJ 切入点 - 识别创建的对象类型

java - Tomcat 中的 Aspectj 与 Web 应用程序

c - stdbool.h 和 float.h 库未链接到我的程序

eclipse - GWT 编译使 JVM 崩溃

java - AspectJ + Gradle 配置

maven - 我可以通过 Maven 运行特定的 testng 测试组吗?

maven - 如何使用 Maven 修改 POM 文件的设置以支持 Artifactory 上的访问 token