java.lang.IncompatibleClassChangeError appears when starting Spring Boot 2.1.1 and Java 11 applications

java.lang.IncompatibleClassChangeError appears when starting Spring Boot 2.1.1 and Java 11 applications … here is a solution to the problem.

java.lang.IncompatibleClassChangeError appears when starting Spring Boot 2.1.1 and Java 11 applications

When releasing the jdk-11.0.62.1.1.RELEASE application, I came across java.lang.IncompatibleClassChangeError > to migrate an existing spring-boot application from 1.5.3 and Java 8.

IN ADDITION TO THESE SETTINGS, I OVERWROTE THE VERSION OF THE SPRING-BOOT-STARTER DEPENDENCY WITH 2.1.1.RELEASE TO PREVENT INCOMPATIBLE LIBRARY ISSUES. In addition to Java 11, I use groovy 3.0.0-alpha-4 in the same project.

You can find a detailed stack trace below:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pathMappedEndpoints' defined in class path resource  [org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints]: Factory method 'pathMappedEndpoints' threw exception; nested exception is java.lang.IncompatibleClassChangeError: Method org.springframework.boot.actuate.endpoint.web.PathMapper.__AW_getRootPath(Ljava/util/List; Lorg/springframework/boot/actuate/endpoint/EndpointId;)Ljava/lang/String; must be InterfaceMethodref c
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
    at org.springframework.beans.factory.support.ConstructorResolver.__AW_instantiateUsingFactoryMethod(ConstructorResolver.java:607)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.__AW_createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.__AW_doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.__AW_createBean(AbstractAutowireCapableBeanFactory.java:498)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.__AW_getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java)
    at org.springframework.beans.factory.support.AbstractBeanFactory.__AW_doGetBean(AbstractBeanFactory.java:318)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.__AW_preInstantiateSingletons(DefaultListableBeanFactory.java:846)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java)
    at org.springframework.context.support.AbstractApplicationContext.__AW_finishBeanFactoryInitialization(AbstractApplicationContext.java:863)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.__AW_run(SpringApplication.java:316)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java)
    at com.demo.api.Application.__AW_main(Application.java:22)
    at com.demo.api.Application.main(Application.java)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.__AW_main(JarLauncher.java:51)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints]: Factory method ' pathMappedEndpoints' threw exception; nested exception is java.lang.IncompatibleClassChangeError: Method org.springframework.boot.actuate.endpoint.web.PathMapper.__AW_getRootPath(Ljava/util/List; Lorg/springframework/boot/actuate/endpoint/EndpointId;)Ljava/lang/String; must be InterfaceMethodref c
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.__AW_instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
    ... 36 common frames omitted
Caused by: java.lang.IncompatibleClassChangeError: Method org.springframework.boot.actuate.endpoint.web.PathMapper.__AW_getRootPath(Ljava/util/List; Lorg/springframework/boot/actuate/endpoint/EndpointId;)Ljava/lang/String; must be InterfaceMethodref c
    at org.springframework.boot.actuate.endpoint.web.PathMapper.getRootPath(PathMapper.java)
    at org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointDiscoverer.createEndpoint(ServletEndpointDiscoverer.java:71)
    at org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointDiscoverer.createEndpoint(ServletEndpointDiscoverer.java:42)
    at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.getFilterEndpoint(EndpointDiscoverer.java:328)
    at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.isFilterMatch(EndpointDiscoverer.java:302)
    at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.isEndpointExposed(EndpointDiscoverer.java:270)
    at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.convertToEndpoints(EndpointDiscoverer.java:189)
    at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.discoverEndpoints(EndpointDiscoverer.java:127)
    at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.getEndpoints(EndpointDiscoverer.java:119)
    at org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints.lambda$getEndpoints$1(PathMappedEndpoints.java:70)
    at java.base/java.util.LinkedHashMap$LinkedValues.forEach(LinkedHashMap.java:608)
    at org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints.getEndpoints(PathMappedEndpoints.java:69)
    at org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints.<init>(PathMappedEndpoints.java:63)
    at org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration.pathMappedEndpoints(WebEndpointAutoConfiguration.java:123)
    at org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration$$EnhancerBySpringCGLIB$$7e6a4261. CGLIB$pathMappedEndpoints$1(<generated>)
    at org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration$$EnhancerBySpringCGLIB$$7e6a4261$$FastClassBySpringCGLIB$$9430a0e5.invoke( <generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
    at org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration$$EnhancerBySpringCGLIB$$7e6a4261.pathMappedEndpoints(<generated>)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.__AW_instantiate(SimpleInstantiationStrategy.java:154)
    ... 38 common frames omitted

Solution

The method of __AW_ prefix suggests using ApsectWerkz or AspectJ. Since the error occurs in a method that looks like an auto-generated, it is likely that you are using a version that is not compatible with Java 11.

You should probably first upgrade Groovy 3.0.0-alpha-4 to 3.0.1 , It is not a good idea to use unstable libraries when debugging code generation issues.

Related Problems and Solutions