Springboot tomcat embedded NoSuchMethodError: javax.servlet.ServletContext.addFilter

Springboot tomcat embedded NoSuchMethodError: javax.servlet.ServletContext.addFilter

在尝试将 spring 应用程序转换为 springboot 时,我在尝试启动该应用程序时遇到以下错误:

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
...
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.addFilter(Ljava/lang/String;Ljavax/servlet/Filter;)Ljavax/servlet/FilterRegistration$Dynamic;
at org.springframework.boot.web.servlet.AbstractFilterRegistrationBean.onStartup(AbstractFilterRegistrationBean.java:225)
at org.springframework.boot.web.servlet.FilterRegistrationBean.onStartup(FilterRegistrationBean.java:42)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.selfInitialize(EmbeddedWebApplicationContext.java:229)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.access[=10=]0(EmbeddedWebApplicationContext.java:89)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onStartup(EmbeddedWebApplicationContext.java:213)
at org.springframework.boot.context.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:55)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5604)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
... 6 common frames omitted

我试图在 pom:

中指定 tomcat 版本
<properties>
    ....
    <java.version>1.8</java.version>
    <tomcat.version>7.0.70</tomcat.version>
</properties>

我还继承自 spring-boot-starter-parent:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.0.RELEASE</version>
</parent>

有什么想法吗?

这是我的 dependency:tree

xxx:yyy-integration-tests:jar:1.1.0-SNAPSHOT
+- xxx:yyy-webapp:jar:classes:1.1.0-SNAPSHOT:compile
|  +- xxx:yyy-api:jar:1.1.0-SNAPSHOT:compile
|  |  \- javax.validation:validation-api:jar:1.1.0.Final:compile
|  +- xxx:yyy-share:jar:1.1.0-SNAPSHOT:compile
|  |  +- org.springframework:spring-context:jar:4.3.2.RELEASE:compile
|  |  \- org.springframework.security:spring-security-acl:jar:4.1.1.RELEASE:compile
|  +- xxx:yyy-commons:jar:1.1.0-SNAPSHOT:compile
|  +- xxx.modules:yyy-modules-core:jar:1.1.0-SNAPSHOT:compile
|  |  +- javax.mail:mail:jar:1.4.7:compile
|  |  |  \- javax.activation:activation:jar:1.1:compile
|  |  +- org.springframework.data:spring-data-jpa:jar:1.10.2.RELEASE:compile
|  |  |  +- org.springframework.data:spring-data-commons:jar:1.12.2.RELEASE:compile
|  |  |  \- org.springframework:spring-orm:jar:4.3.2.RELEASE:compile
|  |  +- org.springframework:spring-aspects:jar:4.3.2.RELEASE:compile
|  |  \- joda-time:joda-time:jar:2.9.4:compile
|  +- xxx.modules:yyy-modules-contribution:jar:1.1.0-SNAPSHOT:compile
|  |  \- commons-beanutils:commons-beanutils:jar:1.9.2:compile
|  +- xxx.modules:yyy-modules-search:jar:1.1.0-SNAPSHOT:compile
|  |  \- org.antlr:antlr4-runtime:jar:4.2.1:compile
|  |     +- org.abego.treelayout:org.abego.treelayout.core:jar:1.0.1:compile
|  |     \- org.antlr:antlr4-annotations:jar:4.2.1:compile
|  +- xxx.modules:yyy-modules-administration:jar:1.1.0-SNAPSHOT:compile
|  |  +- zzz.ssacl:springsecurity-acl-nosql:jar:1.0.2:compile
|  |  \- org.springframework.ldap:spring-ldap-core:jar:2.1.0.RELEASE:compile
|  +- xxx.modules:yyy-modules-dashboard:jar:1.1.0-SNAPSHOT:compile
|  +- xxx.thirdparty.marklogic:marklogic-datasource:jar:1.1.0-SNAPSHOT:runtime
|  |  \- com.marklogic:marklogic-xcc:jar:8.0.1:runtime
|  +- xxx.thirdparty.ldap:module-auth-ldap:jar:1.1.0-SNAPSHOT:compile
|  |  \- org.springframework.security:spring-security-ldap:jar:4.1.1.RELEASE:compile
|  +- zzz.ssacl:springsecurity-acl-marklogic:jar:1.0.2:runtime
|  |  \- zzz.mltools:mltools:jar:1.0.5:runtime
|  +- xxx.thirdparty.lnfsie:lnfsie-wsclient:jar:1.1.0-SNAPSHOT:compile
|  |  +- org.springframework.ws:spring-ws-test:jar:2.3.0.RELEASE:compile
|  |  |  \- xmlunit:xmlunit:jar:1.5:compile
|  |  +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
|  |  |  +- org.apache.httpcomponents:httpcore:jar:4.4.5:compile
|  |  |  \- commons-codec:commons-codec:jar:1.10:compile
|  |  \- commons-collections:commons-collections:jar:3.2.2:compile
|  +- org.springframework:spring-webmvc:jar:4.3.2.RELEASE:compile
|  |  \- org.springframework:spring-expression:jar:4.3.2.RELEASE:compile
|  +- org.springframework:spring-web:jar:4.3.2.RELEASE:compile
|  +- org.springframework:spring-context-support:jar:4.3.2.RELEASE:compile
|  +- org.springframework.security:spring-security-web:jar:4.1.1.RELEASE:compile
|  |  \- aopalliance:aopalliance:jar:1.0:compile
|  +- org.springframework.security:spring-security-config:jar:4.1.1.RELEASE:compile
|  +- org.springframework.security:spring-security-taglibs:jar:4.1.1.RELEASE:compile
|  +- cglib:cglib-nodep:jar:2.2.2:compile
|  +- zzz.qqq:core-api:jar:1.0.5:compile
|  +- zzz.qqq:core-commons:jar:1.0.5:compile
|  +- zzz.qqq:core-web:jar:1.0.5:compile
|  |  +- org.freemarker:freemarker:jar:2.3.25-incubating:compile
|  |  +- javax.servlet:servlet-api:jar:2.5:compile
|  |  +- commons-fileupload:commons-fileupload:jar:1.2.2:compile
|  |  +- org.springframework:spring-jdbc:jar:4.3.2.RELEASE:compile
|  |  +- org.springframework:spring-tx:jar:4.3.2.RELEASE:compile
|  |  \- com.asual.lesscss:lesscss-engine:jar:1.4.2:compile
|  |     \- org.mozilla:rhino:jar:1.7R4:compile
|  +- org.springframework:spring-aop:jar:4.3.2.RELEASE:compile
|  +- org.aspectj:aspectjweaver:jar:1.8.9:compile
|  +- org.aspectj:aspectjrt:jar:1.8.9:compile
|  +- org.codehaus.janino:janino:jar:2.7.8:compile
|  |  \- org.codehaus.janino:commons-compiler:jar:2.7.8:compile
|  +- com.thetransactioncompany:cors-filter:jar:1.7.1:compile
|  |  \- com.thetransactioncompany:java-property-utils:jar:1.9:compile
|  \- net.sf.ehcache:ehcache-core:jar:2.6.6:runtime
+- xxx:yyy-webapp:pom:1.1.0-SNAPSHOT:compile
+- xxx:yyy-commons:test-jar:tests:1.1.0-SNAPSHOT:compile
|  +- org.springframework.security:spring-security-core:jar:4.1.1.RELEASE:compile
|  +- commons-io:commons-io:jar:2.4:compile
|  +- eu.medsea.mimeutil:mime-util:jar:2.1.3:compile
|  +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
|  +- xml-resolver:xml-resolver:jar:1.2:compile
|  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.1:compile
|  +- com.fasterxml.jackson.core:jackson-core:jar:2.3.1:compile
|  +- com.fasterxml.jackson.core:jackson-databind:jar:2.3.1:compile
|  \- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.3.1:compile
+- org.springframework.ws:spring-ws-core:jar:2.2.2.RELEASE:test
|  +- org.springframework.ws:spring-xml:jar:2.2.2.RELEASE:compile
|  +- org.springframework:spring-beans:jar:4.3.2.RELEASE:compile
|  +- org.springframework:spring-core:jar:4.3.2.RELEASE:compile
|  \- org.springframework:spring-oxm:jar:4.3.2.RELEASE:test
+- org.springframework.boot:spring-boot-starter-web:jar:1.4.0.RELEASE:compile
|  +- org.springframework.boot:spring-boot-starter:jar:1.4.0.RELEASE:compile
|  |  +- org.springframework.boot:spring-boot:jar:1.4.0.RELEASE:compile
|  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.0.RELEASE:compile
|  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.4.0.RELEASE:compile
|  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.21:compile
|  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.21:compile
|  |  \- org.yaml:snakeyaml:jar:1.17:runtime
|  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.4.0.RELEASE:compile
|  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:7.0.70:compile
|  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:7.0.70:compile
|  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:7.0.70:compile
|  \- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile
|     +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
|     \- com.fasterxml:classmate:jar:1.3.1:compile
+- org.apache.tomcat:tomcat-util:jar:7.0.70:runtime
|  +- org.apache.tomcat:tomcat-juli:jar:7.0.70:runtime
|  \- org.apache.tomcat:tomcat-api:jar:7.0.70:runtime
|     \- org.apache.tomcat:tomcat-servlet-api:jar:7.0.70:runtime
+- net.sf.saxon:Saxon-HE:jar:9.5.1-8:compile
+- org.apache.commons:commons-lang3:jar:3.3.2:compile
+- org.slf4j:slf4j-api:jar:1.7.21:compile
+- org.slf4j:jcl-over-slf4j:jar:1.7.21:compile
+- org.springframework:spring-test:jar:4.3.2.RELEASE:compile
+- junit:junit:jar:4.12:test
+- org.hamcrest:hamcrest-core:jar:1.3:test
+- org.hamcrest:hamcrest-library:jar:1.3:test
+- org.mockito:mockito-core:jar:1.10.19:test
|  \- org.objenesis:objenesis:jar:2.1:test
+- org.xmlunit:xmlunit-core:jar:2.0.0-alpha-03:test
+- org.xmlunit:xmlunit-legacy:jar:2.0.0-alpha-03:test
+- org.xmlunit:xmlunit-matchers:jar:2.0.0-alpha-03:test
+- org.skyscreamer:jsonassert:jar:1.2.3:test
|  \- org.json:json:jar:20140107:test
+- com.jayway.jsonpath:json-path:jar:0.8.1:test
|  +- net.minidev:json-smart:jar:1.1.1:test
|  \- commons-lang:commons-lang:jar:2.6:compile
+- ch.qos.logback:logback-core:jar:1.1.7:test
\- ch.qos.logback:logback-classic:jar:1.1.7:test

有什么想法吗?

Spring 引导需要 Servlet 3.0 或更高版本。 zzz.qqq:core-web:jar:1.0.5 依赖于 Servlet 2.5。您应该更新您的 pom 以排除它。