spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.25k stars 40.7k forks source link

Mertics: java.lang.NoSuchFieldError: BEST_MATCHING_HANDLER_ATTRIBUTE after upgrading to SB 2.1.2.RELEASE #15860

Closed igdianov closed 5 years ago

igdianov commented 5 years ago

We are facing a problem with WebMvcMetricsFilter after upgrading to SB 2.1.2 from 2.0.0. The error is following:

2019-02-06 23:59:41.252 ERROR [query,,,] 1 --- [nio-8080-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Filter execution threw an exception] with root cause

java.lang.NoSuchFieldError: BEST_MATCHING_HANDLER_ATTRIBUTE
        at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.record(WebMvcMetricsFilter.java:163)
        at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:125)
        at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:106)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.keycloak.adapters.tomcat.AbstractAuthenticatedActionsValve.invoke(AbstractAuthenticatedActionsValve.java:67)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
        at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.invoke(AbstractKeycloakAuthenticatorValve.java:181)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.base/java.lang.Thread.run(Thread.java:834)

There are two workarounds available that fix the error when running the application:

a. Downgrade to SB 2.0.0.RELEASE b. Disable MetricsAutoConfiguration with @SpringBootApplication(exclude = MetricsAutoConfiguration.class)

Any ideas what is causing the problem?

snicoll commented 5 years ago

BEST_MATCHING_HANDLER_ATTRIBUTE has been introduced in Spring Framework 5.1.3.RELEASE so you must be overriding the Spring Framework version somehow. Please don't do that, especially for the core framework, as every upgrade forces you to review all your overrides and make sure they are still accurate.

If that doesn't help, you can share a sample that exhibits the problem and we can reopen this issue.

sylvain-rouquette commented 5 years ago

I also have this problem while upgrading from 2.0.6 to 2.0.8. spring-core is 5.0.12, spring-web 5.0.10, spring-security 5.0.9. But everything is pulled from spring-boot-starters without version, since versions are in the parent.

snicoll commented 5 years ago

@sylvain-rouquette the field was added in 5.0.11.RELEASE. I've already mentioned we can have a look to a sample if you provide one.

wilkinsona commented 5 years ago

If you have spring-core 5.0.12 and spring-web 5.0.10 then the parent isn't controlling the versions. It will give you a consistent version of all Spring Framework modules. With Boot 2.0.8 that'll be Framework 5.0.12.

sylvain-rouquette commented 5 years ago

I created a small repo with some curated files: https://github.com/InceptoMedical/spring-boot-public

there is the dependency tree, and the stacktrace where I see the bug (unit test). Let me know if this will be enough.

snicoll commented 5 years ago

Thanks but that project does not build for me.

Downloading from spring-repo: https://repo.spring.io/release/org/springframework/cloud/spring-cloud-sleuth/$%7Bspring-cloud-sleuth.version%7D/spring-cloud-sleuth-$%7Bspring-cloud-sleuth.version%7D.pom
Downloading from spring-plugins: https://repo.spring.io/plugins-release/org/springframework/cloud/spring-cloud-sleuth/$%7Bspring-cloud-sleuth.version%7D/spring-cloud-sleuth-$%7Bspring-cloud-sleuth.version%7D.pom
Downloading from spring-milestones: https://repo.spring.io/milestone/org/springframework/cloud/spring-cloud-sleuth/$%7Bspring-cloud-sleuth.version%7D/spring-cloud-sleuth-$%7Bspring-cloud-sleuth.version%7D.pom
Downloading from www.dcm4che.org: http://www.dcm4che.org/maven2/org/springframework/cloud/spring-cloud-sleuth/$%7Bspring-cloud-sleuth.version%7D/spring-cloud-sleuth-$%7Bspring-cloud-sleuth.version%7D.pom
wilkinsona commented 5 years ago

Also, spring-cloud-sleuth isn't intended to be used as a bom. I suspect whatever version of it you are using is downgrading some of Framework's modules. Sleuth's modules are already managed by spring-cloud-dependencies so you can just remove it. If I do that and remove the <modules>, your project has a consistent set of versions for the Spring Framework dependencies:

[INFO] com.incepto.cloud:parent:pom:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-validation:jar:2.0.8.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.0.8.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:2.0.8.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.8.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.8.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO] |  |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.19:runtime
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.37:compile
[INFO] |  \- org.hibernate.validator:hibernate-validator:jar:6.0.14.Final:compile
[INFO] |     +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] |     +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |     \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] +- org.springframework.boot:spring-boot-configuration-processor:jar:2.0.8.RELEASE:compile (optional) 
[INFO] +- org.projectlombok:lombok:jar:1.18.4:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.0.8.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.0.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-web:jar:5.0.12.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:5.0.12.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.0.12.RELEASE:compile
[INFO] |     +- org.springframework:spring-aop:jar:5.0.12.RELEASE:compile
[INFO] |     +- org.springframework:spring-context:jar:5.0.12.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:5.0.12.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-webflux:jar:2.0.8.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-reactor-netty:jar:2.0.8.RELEASE:compile
[INFO] |  |  \- io.projectreactor.ipc:reactor-netty:jar:0.7.14.RELEASE:compile
[INFO] |  |     +- io.netty:netty-codec-http:jar:4.1.31.Final:compile
[INFO] |  |     |  \- io.netty:netty-codec:jar:4.1.31.Final:compile
[INFO] |  |     +- io.netty:netty-handler:jar:4.1.31.Final:compile
[INFO] |  |     |  +- io.netty:netty-buffer:jar:4.1.31.Final:compile
[INFO] |  |     |  \- io.netty:netty-transport:jar:4.1.31.Final:compile
[INFO] |  |     |     \- io.netty:netty-resolver:jar:4.1.31.Final:compile
[INFO] |  |     +- io.netty:netty-handler-proxy:jar:4.1.31.Final:compile
[INFO] |  |     |  \- io.netty:netty-codec-socks:jar:4.1.31.Final:compile
[INFO] |  |     \- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.31.Final:compile
[INFO] |  |        +- io.netty:netty-common:jar:4.1.31.Final:compile
[INFO] |  |        \- io.netty:netty-transport-native-unix-common:jar:4.1.31.Final:compile
[INFO] |  +- org.springframework:spring-webflux:jar:5.0.12.RELEASE:compile
[INFO] |  \- org.synchronoss.cloud:nio-multipart-parser:jar:1.1.0:compile
[INFO] |     +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |     \- org.synchronoss.cloud:nio-stream-storage:jar:1.1.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-undertow:jar:2.0.8.RELEASE:compile
[INFO] |  +- io.undertow:undertow-core:jar:1.4.26.Final:compile
[INFO] |  |  +- org.jboss.xnio:xnio-api:jar:3.3.8.Final:compile
[INFO] |  |  \- org.jboss.xnio:xnio-nio:jar:3.3.8.Final:runtime
[INFO] |  +- io.undertow:undertow-servlet:jar:1.4.26.Final:compile
[INFO] |  |  \- org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec:jar:1.0.2.Final:compile
[INFO] |  +- io.undertow:undertow-websockets-jsr:jar:1.4.26.Final:compile
[INFO] |  |  \- org.jboss.spec.javax.websocket:jboss-websocket-api_1.1_spec:jar:1.1.3.Final:compile
[INFO] |  +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] |  \- org.glassfish:javax.el:jar:3.0.0:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.6:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.10:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.11:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.8.1:compile
[INFO] +- org.apache.commons:commons-math3:jar:3.6.1:compile
[INFO] +- org.apache.commons:commons-collections4:jar:4.2:compile
[INFO] +- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.8:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.9.8:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.9.8:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.8:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.8:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] +- com.github.spotbugs:spotbugs-annotations:jar:3.1.11:compile (optional) 
[INFO] |  \- com.google.code.findbugs:jsr305:jar:3.0.2:compile (optional) 
[INFO] +- net.jodah:expiringmap:jar:0.5.9:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.0.8.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.0.8.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.0.8.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] |  |  \- net.minidev:json-smart:jar:2.3:test
[INFO] |  |     \- net.minidev:accessors-smart:jar:1.2:test
[INFO] |  |        \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.assertj:assertj-core:jar:3.9.1:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:5.0.12.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.0.12.RELEASE:compile
[INFO] |  +- org.springframework:spring-test:jar:5.0.12.RELEASE:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.5.1:test
[INFO] +- org.mockito:mockito-core:jar:2.24.0:test
[INFO] |  +- net.bytebuddy:byte-buddy-agent:jar:1.7.11:test
[INFO] |  \- org.objenesis:objenesis:jar:2.6:test
[INFO] +- net.bytebuddy:byte-buddy:jar:1.9.9:test
[INFO] +- org.springframework.security:spring-security-test:jar:5.0.11.RELEASE:test
[INFO] |  +- org.springframework.security:spring-security-core:jar:5.0.11.RELEASE:test
[INFO] |  \- org.springframework.security:spring-security-web:jar:5.0.11.RELEASE:test
[INFO] \- io.projectreactor:reactor-test:jar:3.1.14.RELEASE:test
[INFO]    \- io.projectreactor:reactor-core:jar:3.1.14.RELEASE:compile
[INFO]       \- org.reactivestreams:reactive-streams:jar:1.0.2:compile
sylvain-rouquette commented 5 years ago

Thanks for your feedbacks, I'll update my project with your inputs.

edit: you were right, spring-cloud-sleuth, and how I imported it, was the culprit. Thanks again.

xkcoding commented 5 years ago

how to solve this problem?? @igdianov

snicoll commented 5 years ago

@xkcoding there is already some context in this very issue https://github.com/spring-projects/spring-boot/issues/15860#issuecomment-461316394. If you need assistance, please ask on StackOverflow or come chat with the community on Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.

mutchakala commented 5 years ago

Is there any fix for this issue? issue is driving my nuts

snicoll commented 5 years ago

@mutchakala in the comment just above yours. Please take the time reading through the history before adding a comment.