升级到Spring-Boot 1.5.9(从1.3.x开始) - ServletRegistrationBean的ClassNotFoundException

时间:2018-04-26 18:49:49

标签: java spring maven spring-boot dependencies

我正在尝试升级到Spring Boot 1.5.9并在编译时,在运行时我得到下面的Exception。我试过切换到下载,尝试更新Spring-Cloud(Edgware,Brixton等等)但没有运气。我知道我的代码没有使用这个类(如果是这样就不会编译)。我如何找到违规的依赖(如果是这样的话)?我的pom.xml很庞大,有很多内部工件,所以张贴整个内容是没有意义的。

java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$EndpointWebMvcConfiguration due to org/springframework/boot/context/embedded/ServletRegistrationBean not found. Make sure your own configuration does not rely on that class. This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:55) ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar!/:1.5.9.RELEASE] ......

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.ServletRegistrationBean
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[?:1.8.0_161]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_161]
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94) ~[lbossvc.jar:2.434.0]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_161]
    at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:1.8.0_161]
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[?:1.8.0_161]
    at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[?:1.8.0_161]
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613) ~[spring-core-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524) ~[spring-core-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510) ~[spring-core-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
    at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:570) ~[spring-core-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:697) ~[spring-beans-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:640) ~[spring-beans-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:609) ~[spring-beans-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1484) ~[spring-beans-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:425) ~[spring-beans-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:395) ~[spring-beans-4.3.13.RELEASE.jar!/:4.3.13.RELEASE]
    at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ManagementServerPort.hasCustomBeanDefinition(EndpointWebMvcAutoConfiguration.java:424) ~[spring-boot-actuator-1.5.9.RELEASE.jar!/:1.5.9.RELEASE]
    at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ManagementServerPort.hasCustomBeanDefinition(EndpointWebMvcAutoConfiguration.java:417) ~[spring-boot-actuator-1.5.9.RELEASE.jar!/:1.5.9.RELEASE]
    at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ManagementServerPort.get(EndpointWebMvcAutoConfiguration.java:368) ~[spring-boot-actuator-1.5.9.RELEASE.jar!/:1.5.9.RELEASE]
    at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$OnManagementMvcCondition.getMatchOutcome(EndpointWebMvcAutoConfiguration.java:345) ~[spring-boot-actuator-1.5.9.RELEASE.jar!/:1.5.9.RELEASE]
    at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar!/:1.5.9.RELEASE]

以下是我的Spring依赖项:

    org.springframework:spring-context:jar:4.3.13.RELEASE:compile
[INFO]    org.springframework.cloud:spring-cloud-starter-netflix-archaius:jar:1.4.4.RELEASE:compile
[INFO]    org.springframework.data:spring-data-commons:jar:1.13.9.RELEASE:compile
[INFO]    org.springframework.restdocs:spring-restdocs-core:jar:1.1.2.RELEASE:test
[INFO]    org.springframework.cloud:spring-cloud-context:jar:1.3.3.RELEASE:compile
[INFO]    org.springframework.cloud:spring-cloud-commons:jar:1.3.3.RELEASE:compile
[INFO]    org.springframework:spring-context-support:jar:4.3.13.RELEASE:compile
[INFO]    org.springframework.security:spring-security-crypto:jar:4.2.3.RELEASE:compile
[INFO]    org.springframework.cloud:spring-cloud-starter-netflix-hystrix:jar:1.4.4.RELEASE:compile
[INFO]    org.springframework:spring-beans:jar:4.3.13.RELEASE:compile
[INFO]    org.springframework:spring-expression:jar:4.3.13.RELEASE:compile
[INFO]    io.springfox:springfox-swagger-ui:jar:2.8.0:compile
[INFO]    org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile
[INFO]    org.springframework:spring-aop:jar:4.3.13.RELEASE:compile
[INFO]    org.springframework.boot:spring-boot-starter-jdbc:jar:1.5.9.RELEASE:compile
[INFO]    io.springfox:springfox-swagger2:jar:2.8.0:compile
[INFO]    org.springframework:spring-core:jar:4.3.13.RELEASE:compile
[INFO]    org.springframework.boot:spring-boot-starter-web:jar:1.5.9.RELEASE:compile
[INFO]    io.springfox:springfox-spi:jar:2.8.0:compile
[INFO]    org.springframework.boot:spring-boot-starter-test:jar:1.5.9.RELEASE:test
[INFO]    org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile
[INFO]    org.springframework:spring-jdbc:jar:4.3.13.RELEASE:compile
[INFO]    org.springframework.boot:spring-boot-test:jar:1.5.9.RELEASE:test
[INFO]    org.springframework.boot:spring-boot-starter-actuator:jar:1.5.9.RELEASE:compile
[INFO]    io.springfox:springfox-schema:jar:2.8.0:compile
[INFO]    io.springfox:springfox-core:jar:2.8.0:compile
[INFO]    org.springframework.cloud:spring-cloud-starter:jar:1.3.3.RELEASE:compile
[INFO]    org.springframework.data:spring-data-keyvalue:jar:1.2.9.RELEASE:compile
[INFO]    org.springframework.security:spring-security-rsa:jar:1.0.3.RELEASE:compile
[INFO]    org.springframework.data:spring-data-redis:jar:1.7.5.RELEASE:compile
[INFO]    org.springframework:spring-oxm:jar:4.3.13.RELEASE:compile
[INFO]    org.springframework.boot:spring-boot-configuration-processor:jar:1.5.9.RELEASE:compile
[INFO]    org.springframework.boot:spring-boot-starter-undertow:jar:1.5.9.RELEASE:compile
[INFO]    org.springframework:spring-test:jar:4.3.13.RELEASE:compile
[INFO]    org.springframework.cloud:spring-cloud-netflix-core:jar:1.4.4.RELEASE:compile
[INFO]    org.springframework.restdocs:spring-restdocs-mockmvc:jar:1.1.2.RELEASE:test
[INFO]    org.springframework.boot:spring-boot-actuator:jar:1.5.9.RELEASE:compile
[INFO]    org.springframework.retry:spring-retry:jar:1.0.3.RELEASE:compile
[INFO]    org.springframework.boot:spring-boot-starter:jar:1.5.9.RELEASE:compile
[INFO]    org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.9.RELEASE:test
[INFO]    io.springfox:springfox-swagger-common:jar:2.8.0:compile
[INFO]    io.springfox:springfox-spring-web:jar:2.8.0:compile
[INFO]    org.springframework:spring-web:jar:4.3.13.RELEASE:compile
[INFO]    org.springframework.boot:spring-boot-starter-log4j2:jar:1.5.9.RELEASE:compile
[INFO]    org.springframework:spring-tx:jar:4.3.13.RELEASE:compile
[INFO]    org.springframework.boot:spring-boot:jar:1.5.9.RELEASE:compile
[INFO]    org.springframework.cloud:spring-cloud-starter-hystrix:jar:1.4.4.RELEASE:compile
[INFO]    org.springframework:spring-jmx:jar:2.0.8:compile
[INFO]    org.springframework.boot:spring-boot-autoconfigure:jar:1.5.9.RELEASE:compile
[INFO]    org.springframework:spring-webmvc:jar:4.3.13.RELEASE:compile
[INFO]    org.springframework.boot:spring-boot-starter-aop:jar:1.5.9.RELEASE:compile

1 个答案:

答案 0 :(得分:0)

事实证明,我的假设是正确的 - 我的一个内部依赖是从早期的Spring-Boot版本(上下文包vs web包)导入ServletRegistrationBean。有两种可能的修复,因为我不确定我是否可以更新依赖项。一种是创建一个完全限定的类,只使用旧包扩展ServletRegistrationBean,另一种是更新依赖项。两者都有效,尽管前者非常黑客。谢天谢地,我可以更新相关代码,这就是我修复它的方法。