title: Spring WebApplicationInitializer (ServletContainerInitializer, @HandlesTypes) with Embedded Tomcat
body: <p>I fail to understand why in the following minimal project my implementation of Spring's <code>WebApplicationInitializer</code> interface is found when running tests within Eclipse and IntelliJ, but not when using Maven (<code>mvn clean test</code>).</p>
  
  <p>With Eclipse and IntellIJ I see <code>INFO: Spring WebApplicationInitializers detected on classpath: [com.example.pack.DummyInitializer@26d678a4]</code></p>
  
  <p>With <code>mvn clean test</code> I see <code>INFO: No Spring WebApplicationInitializer types detected on classpath</code>.</p>
  
  <p>In the test I start an Embedded Tomcat:</p>
  
  <pre><code>String pathToWebXML = new File("src/main/webapp/").getAbsolutePath();
  tomcat = new Tomcat();
  tomcat.setBaseDir("embedded_tomcat");
  tomcat.setPort(0);
  tomcat.addWebapp("", pathToWebXML);
  tomcat.start();
  </code></pre>
  
  <p>The <code>web.xml</code> references a <code>ServletContextListener</code> implementation which creates a new (and empty) <code>AnnotationConfigWebApplicationContext</code>.</p>
  
  <p>I uploaded the example project to GitHub: <a href="https://github.com/C-Otto/webapplicationinitializer" rel="nofollow">https://github.com/C-Otto/webapplicationinitializer</a></p>