When using spring-context-indexer , getting the error on spring boot startup
HI Iam using spring cloud function and spring context indexer( to reduce the startup time of spring boot container). When i run the spring boot getting the following error
Caused by: java.lang.IllegalStateException: Bean class name [XXX.XXX.XXX.XXX] has not been resolved into an actual Class
at org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClass(AbstractBeanDefinition.java:410) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration$ContextFunctionRegistry.findType(ContextFunctionCatalogAutoConfiguration.java:576) ~[spring-cloud-function-context-1.0.0.RC2.jar:1.0.0.RC2]
This because when the bean is getting created from the index, its not able to find the source (path)of the actual bean .
If i remove the indexer from my POM then its working fine, also in debug i can see the source filed of the BeanDefinition is populated with the actual path of the class file.
ContextFunctionCatalogAutoConfiguration$ContextFunctionRegistry.findType be modified to load the beans from index correctly
Below are the stack trace during spring-boot startup
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'functionCatalog' defined in class path resource [org/springframework/cloud/function/context/config/ContextFunctionCatalogAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.function.context.FunctionRegistry]: Factory method 'functionCatalog' threw exception; nested exception is java.lang.IllegalStateException: Bean class name [com.XXXXX.XXXXX.XXXXX] has not been resolved into an actual Class
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:587) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1254) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1103) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at com.XXXX.XXXXX.XXXXXX.main(XXXXX.java:39) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.function.context.FunctionRegistry]: Factory method 'functionCatalog' threw exception; nested exception is java.lang.IllegalStateException: Bean class name [XXX.XXX.XXX.XXX] has not been resolved into an actual Class
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
... 18 common frames omitted
Caused by: java.lang.IllegalStateException: Bean class name [com.XXXX.XXXX.XXXX] has not been resolved into an actual Class
at org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClass(AbstractBeanDefinition.java:410) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration$ContextFunctionRegistry.findType(ContextFunctionCatalogAutoConfiguration.java:576) ~[spring-cloud-function-context-1.0.0.RC2.jar:1.0.0.RC2]
at org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration$ContextFunctionRegistry.findType(ContextFunctionCatalogAutoConfiguration.java:671) ~[spring-cloud-function-context-1.0.0.RC2.jar:1.0.0.RC2]
at org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration$ContextFunctionRegistry.wrap(ContextFunctionCatalogAutoConfiguration.java:439) ~[spring-cloud-function-context-1.0.0.RC2.jar:1.0.0.RC2]
at org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration$ContextFunctionRegistry.merge(ContextFunctionCatalogAutoConfiguration.java:417) ~[spring-cloud-function-context-1.0.0.RC2.jar:1.0.0.RC2]
at org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration.functionCatalog(ContextFunctionCatalogAutoConfiguration.java:115) ~[spring-cloud-function-context-1.0.0.RC2.jar:1.0.0.RC2]
at org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration$$EnhancerBySpringCGLIB$$7b13a961.CGLIB$functionCatalog$0(<generated>) ~[spring-cloud-function-context-1.0.0.RC2.jar:1.0.0.RC2]
at org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration$$EnhancerBySpringCGLIB$$7b13a961$$FastClassBySpringCGLIB$$1448911b.invoke(<generated>) ~[spring-cloud-function-context-1.0.0.RC2.jar:1.0.0.RC2]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration$$EnhancerBySpringCGLIB$$7b13a961.functionCatalog(<generated>) ~[spring-cloud-function-context-1.0.0.RC2.jar:1.0.0.RC2]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_141]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_141]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_141]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_141]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
... 19 common frames omitted
FYI-This error is not coming in 1.0.0.M5 version
I doubt if it really helps much to use the indexer, so if I were you I'd just carry on without it, until we can find out what broke.
The function-sample-pojo works for me, actually, when I add the indexer. Do you have a project that reproduces the error?
@klnsarma have you had a chance to look into that based on Dave's comment above?
I faced the same issue. And after I commented the indexer dependency in pom it started working.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-indexer</artifactId>
<version>${spring.version}</version>
<optional>true</optional>
</dependency>
I have just played with it and can't reproduce it either. Further more if it is still an issue it appears to be not related to SCF. Given there is no follow up and no way to reproduce it, I will close this as "won't fix" for now, but as Dave suggested if one can produce a reproducible sample we'll be glad to revisit it.