Search code examples
javaeclipsemavenspring-bootm2e

How to configure Spring Boot 1.2.0 for Servlet 3.0 and have m2e set Eclipse Facet to 3.0?


With Spring Boot 1.2.0, m2e sets the Eclipse Project Facet "Dynamic Web Project" to 3.1. This is expected as Spring Boot 1.2.0 newly supports Servlet Spec 3.1.

However, we need to stay with 3.0 (Tomcat 7), so we set the correct property in our POM per the Boot instructions:

<servlet-api.version>3.0.1</servlet-api.version>

But m2e still sets the Eclipse facet to 3.1, not 3.0. The problem is Eclipse will not deploy the war to Tomcat 7.

What else needs setting to make m2e set the facet to 3.0 so we can upgrade to Spring Boot 1.2.0?


Solution

  • I found a simple solution: m2e-wtp sets the Eclipse project web facet by looking at web.xml (if it exists) or scanning the classpath for specific servlet api classes (when web.xml not found).

    Therefore, either set the servlet api version in web.xml or set POM property to a non-servlet 3.1 version (e.g. the Spring Boot 1.1.10's version is 7.0.57). Either approach causes m2e-wtp to set the facet accordingly.

    I am wondering if it is possible to improve m2e-wtp's detection or configuration as currently I don't know how it is possible in this configuration to use Tomcat 8 with servlet 3.0 without a web.xml.