2013-11-20 39 views
1

我有一個spring roo項目,可以在sts/eclipse下運行。然而,當我運行Maven [mvn package],我係統地得到以下錯誤aspectj-maven-plugin的編譯目標的奇怪問題

[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("/"); 

    } 
} 

任何人都可以請幫助?

回答

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>