Question

I have a spring roo project that I can build and run under sts/eclipse. However, when I run maven [mvn package], I systematically get the following errors:

[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]

Here is my WebApplicationInitializer class:

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

    }
}

Can anyone please help?

Was it helpful?

Solution

It turns out it was yet another issue with a maven dependency i.e. jstl impl.

By excluding the wrong version of the servlet api transitive dependency, the compilation errors were gone.

See below:

<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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top