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.39k stars 40.73k forks source link

Adding spring-cloud-starter-openfeign causes native image application error on startup #33248

Closed nickcodefresh closed 2 years ago

nickcodefresh commented 2 years ago

If I add org.springframework.cloud:spring-cloud-starter-openfeign to my POM and then run mvn -Pnative -DskipTests clean package the resulting native application fails to start with:

➜  target git:(SB3-test) ✗ ./flex-tbc-service                     
10:26:05.276 [main] DEBUG com.ooyala.flex.tbc.Application - Starting TBC service

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v3.0.0-RC1)

2022-11-18T10:26:05.374Z  INFO 245196 --- [           main] com.ooyala.flex.tbc.Application          : Starting AOT-processed Application using Java 19.0.1 on hp-zbook-fury with PID 245196 (/home/nsmith/Documents/trunk/microservices/flex-javatemplate-service/Service/target/flex-tbc-service started by nsmith in /home/nsmith/Documents/trunk/microservices/flex-javatemplate-service/Service/target)
2022-11-18T10:26:05.374Z  INFO 245196 --- [           main] com.ooyala.flex.tbc.Application          : No active profile set, falling back to 1 default profile: "default"
2022-11-18T10:26:05.376Z  INFO 245196 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=5f8f2878-2132-3d70-a743-72d0a869712e
2022-11-18T10:26:05.380Z  WARN 245196 --- [           main] o.s.c.annotation.AnnotationTypeMapping   : Support for convention-based annotation attribute overrides is deprecated and will be removed in Spring Framework 6.1. Please annotate the following attributes in @org.springframework.retry.annotation.EnableRetry with appropriate @AliasFor declarations: [proxyTargetClass]
2022-11-18T10:26:05.382Z  INFO 245196 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.integration.config.IntegrationManagementConfiguration' of type [org.springframework.integration.config.IntegrationManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-11-18T10:26:05.396Z  INFO 245196 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 18100 (http)
2022-11-18T10:26:05.396Z  INFO 245196 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-11-18T10:26:05.396Z  INFO 245196 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.0.27]
2022-11-18T10:26:05.401Z  INFO 245196 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-11-18T10:26:05.401Z  INFO 245196 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 27 ms
2022-11-18T10:26:05.407Z  WARN 245196 --- [           main] i.m.c.i.binder.jvm.JvmGcMetrics          : GC notifications will not be available because MemoryPoolMXBeans are not provided by the JVM
2022-11-18T10:26:05.477Z  INFO 245196 --- [           main] o.s.c.s.m.DirectWithAttributesChannel    : Channel 'flex-tbc-service.springCloudBusInput' has 1 subscriber(s).
2022-11-18T10:26:05.517Z  WARN 245196 --- [           main] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. While this cache implementation is useful for development and tests, it's recommended to use Caffeine cache in production.You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.
2022-11-18T10:26:05.521Z  INFO 245196 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 1 endpoint(s) beneath base path '/actuator'
2022-11-18T10:26:05.534Z  INFO 245196 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2022-11-18T10:26:05.534Z  INFO 245196 --- [           main] o.s.i.channel.PublishSubscribeChannel    : Channel 'flex-tbc-service.errorChannel' has 1 subscriber(s).
2022-11-18T10:26:05.534Z  INFO 245196 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started bean '_org.springframework.integration.errorLogger'
2022-11-18T10:26:05.535Z  INFO 245196 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 18100 (http) with context path ''
2022-11-18T10:26:05.535Z  WARN 245196 --- [           main] w.s.c.ServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'
2022-11-18T10:26:05.535Z  INFO 245196 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2022-11-18T10:26:05.535Z  INFO 245196 --- [           main] o.s.i.channel.PublishSubscribeChannel    : Channel 'flex-tbc-service.errorChannel' has 0 subscriber(s).
2022-11-18T10:26:05.535Z  INFO 245196 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : stopped bean '_org.springframework.integration.errorLogger'
2022-11-18T10:26:05.536Z  INFO 245196 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-11-18T10:26:05.537Z ERROR 245196 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[na:na]
        at java.base@19.0.1/java.lang.Iterable.forEach(Iterable.java:75) ~[flex-tbc-service:na]
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:933) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:587) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[flex-tbc-service:3.0.0-RC1]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[flex-tbc-service:3.0.0-RC1]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432) ~[flex-tbc-service:3.0.0-RC1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[flex-tbc-service:3.0.0-RC1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[flex-tbc-service:3.0.0-RC1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) ~[flex-tbc-service:3.0.0-RC1]
        at com.ooyala.flex.tbc.Application.main(Application.java:31) ~[flex-tbc-service:na]
Caused by: java.lang.NullPointerException: null
        at org.springframework.aop.framework.AdvisedSupport$MethodCacheKey.<init>(AdvisedSupport.java:578) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.aop.framework.AdvisedSupport.getInterceptorsAndDynamicInterceptionAdvice(AdvisedSupport.java:470) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) ~[na:na]
        at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration$$SpringCGLIB$$0.setPortIfNeeded(<generated>) ~[flex-tbc-service:na]
        at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistrationListener.onApplicationEvent(ConsulAutoServiceRegistrationListener.java:59) ~[flex-tbc-service:na]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[na:na]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[na:na]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:413) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:370) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:47) ~[na:na]
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[flex-tbc-service:6.0.0-RC2]
        ... 13 common frames omitted

2022-11-18T10:26:05.537Z ERROR 245196 --- [           main] com.ooyala.flex.tbc.Application          : eeee

org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[na:na]
        at java.base@19.0.1/java.lang.Iterable.forEach(Iterable.java:75) ~[flex-tbc-service:na]
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:933) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:587) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[flex-tbc-service:3.0.0-RC1]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[flex-tbc-service:3.0.0-RC1]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432) ~[flex-tbc-service:3.0.0-RC1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[flex-tbc-service:3.0.0-RC1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[flex-tbc-service:3.0.0-RC1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) ~[flex-tbc-service:3.0.0-RC1]
        at com.ooyala.flex.tbc.Application.main(Application.java:31) ~[flex-tbc-service:na]
Caused by: java.lang.NullPointerException: null
        at org.springframework.aop.framework.AdvisedSupport$MethodCacheKey.<init>(AdvisedSupport.java:578) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.aop.framework.AdvisedSupport.getInterceptorsAndDynamicInterceptionAdvice(AdvisedSupport.java:470) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) ~[na:na]
        at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration$$SpringCGLIB$$0.setPortIfNeeded(<generated>) ~[flex-tbc-service:na]
        at org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistrationListener.onApplicationEvent(ConsulAutoServiceRegistrationListener.java:59) ~[flex-tbc-service:na]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[na:na]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[na:na]
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:413) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:370) ~[flex-tbc-service:6.0.0-RC2]
        at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:47) ~[na:na]
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[flex-tbc-service:6.0.0-RC2]
        ... 13 common frames omitted

Running the non-native application works fine, and removing this dependency also allows the application to start up as normal.

Any idea what this might be? I'm running Spring Boot 3.0.0-RC1, Sping Cloud 4.0.0-SNAPSHOT (locally compiled) and GraalVM CE 22.3.0 JDK.

wilkinsona commented 2 years ago

Duplicates https://github.com/spring-cloud/spring-cloud-openfeign/issues/742.

d-eder commented 1 year ago

I still have the same issue with spring-cloud 2022.0.1. But it seems to be related to consul. If you set the application property spring.cloud.service-registry.auto-registration.enabled=false the issue doesn't happen again. It seems that the method org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration#setPortIfNeeded is the culprit.