spring-cloud-commons icon indicating copy to clipboard operation
spring-cloud-commons copied to clipboard

AOT NamedContextFactory registerBeans(GenericApplicationContext must be an instance of interface AnnotationConfigRegistry)

Open enderwsp opened this issue 6 months ago • 4 comments

Describe the bug Please provide details of the problem, including the version of Spring Cloud that you are using.

springboot 3.4.6 springcloud 2024.0.1 spring-cloud-starter-neflix-eureka-client 4.2.1 spring-cloud-balancer 4.2.1 spring-context 6.2.7

here the stack:

ava.lang.IllegalArgumentException: Object of class [org.springframework.context.support.GenericApplicationContext] must be an instance of interface rg.springframework.context.annotation.AnnotationConfigRegistry at org.springframework.util.Assert.instanceCheckFailed(Assert.java:618) at org.springframework.util.Assert.isInstanceOf(Assert.java:513) at org.springframework.util.Assert.isInstanceOf(Assert.java:546) at org.springframework.cloud.context.named.NamedContextFactory.registerBeans(NamedContextFactory.java:144) at org.springframework.cloud.context.named.NamedContextFactory.createContext(NamedContextFactory.java:138) at org.springframework.cloud.context.named.NamedContextFactory.getContext(NamedContextFactory.java:123) at org.springframework.cloud.context.named.NamedContextFactory.getInstances(NamedContextFactory.java:254) at org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient.getSupportedLifecycleProcessors(BlockingLoadBalancerClie t.java:143) at org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient.execute(BlockingLoadBalancerClient.java:72) at org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:55) at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:88) at com.spdb.communication.interceptor.RequestHeaderInterceptor.intercept(RequestHeaderInterceptor.java:28) at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:88) at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:72) at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:81) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:900) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:801) at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:549)

Sample If possible, please provide a test case or sample application that reproduces the problem. This makes it much easier for us to diagnose the problem and to verify that we have fixed it.

enderwsp avatar Jun 26 '25 05:06 enderwsp

if i copy target to local workspace,try to debug on aot mode,then found the type IS GenericApplicationContext its parent IS ServletWebServerApplicationContext

enderwsp avatar Jun 26 '25 06:06 enderwsp

on jvm mode

Type is AnnotationConfigApplicationContext

Parent is. AnnotationConfigServletWebServerApplicationContext

enderwsp avatar Jun 26 '25 06:06 enderwsp

in file https://github.com/spring-cloud/spring-cloud-commons/blob/main/spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java

The following logic is incompatible:

context = AotDetector.useGeneratedArtifacts() ? new GenericApplicationContext(beanFactory) : new AnnotationConfigApplicationContext(beanFactory);

enderwsp avatar Jun 26 '25 06:06 enderwsp