与aspectj-maven-plugin的编译目标有关的奇怪问题

时间:2013-11-20 18:07:35

标签: 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("/");

    }
}

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

事实证明这是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>