spring-cloud-netflix: FileNotFoundException using jdk 11

version: Finchley.RELEASE

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/boot/context/properties/EnableConfigurationPropertiesImportSelector$ConfigurationPropertiesBeanRegistrar.class] cannot be opened because it does not exist
	at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:646)
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:303)
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:202)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:170)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:688)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:530)
	at org.springframework.cloud.context.named.NamedContextFactory.createContext(NamedContextFactory.java:117)
	at org.springframework.cloud.context.named.NamedContextFactory.getContext(NamedContextFactory.java:85)
	at org.springframework.cloud.netflix.ribbon.SpringClientFactory.getContext(SpringClientFactory.java:118)
	at org.springframework.cloud.context.named.NamedContextFactory.getInstance(NamedContextFactory.java:126)
	at org.springframework.cloud.netflix.ribbon.SpringClientFactory.getInstance(SpringClientFactory.java:108)
	at org.springframework.cloud.netflix.ribbon.SpringClientFactory.getClientConfig(SpringClientFactory.java:65)
	at org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient.getClientConfig(LoadBalancerFeignClient.java:78)
	at org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient.execute(LoadBalancerFeignClient.java:62)
	at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:97)
	at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
	at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
	at com.sun.proxy.$Proxy131.entrust(Unknown Source)
	at com.polarisex.dragon.engine.sub.QuoteCallBackImpl.orderCallBack(QuoteCallBackImpl.java:79)
	at com.polarisex.dragon.engine.AbstractQuoteProcess.callBack(AbstractQuoteProcess.java:86)
	at com.polarisex.dragon.engine.sub.AbstractQuoteProcessImpl.orderCallBack(AbstractQuoteProcessImpl.java:123)
	at com.polarisex.dragon.engine.sub.AbstractQuoteProcessImpl.processOrder(AbstractQuoteProcessImpl.java:134)
	at com.polarisex.dragon.engine.sub.AbstractQuoteProcessImpl.run(AbstractQuoteProcessImpl.java:42)
	at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.io.FileNotFoundException: class path resource [org/springframework/boot/context/properties/EnableConfigurationPropertiesImportSelector$ConfigurationPropertiesBeanRegistrar.class] cannot be opened because it does not exist
	at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180)
	at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:51)
	at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)
	at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:123)
	at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81)
	at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:732)
	at org.springframework.context.annotation.ConfigurationClassParser.asSourceClasses(ConfigurationClassParser.java:711)
	at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:617)
	... 28 more

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 43 (23 by maintainers)

Commits related to this issue

Most upvoted comments

I think the URL handler is a red herring. When the ClassLoader is wrong, EnableConfigurationPropertiesImportSelector$ConfigurationPropertiesBeanRegistrar.class isn’t on the class path of the ClassLoader that tries to load it so it’s correct that it fails to load.

When SpringClientFactory creates a context, it’s assuming that the thread context class loader will be the class loader that should be used by the child context. That holds true on Java 8 but does not hold true on Java 11. When running on Java 8, the TCCL is a TomcatEmbeddedWebappClassLoader. When running on Java 11, the TCCL is a ClassLoaders$AppClassLoader. The thread in both cases is a worker thread in a fork join pool. This looks like https://bugs.openjdk.java.net/browse/JDK-8172726 to me with the code relying on a bug that’s been fixed in Java 9.

I think the child context should be explicitly configured to use the ClassLoader from its parent:

if (this.parent != null) {
	// Uses Environment from parent as well as beans
	context.setParent(this.parent);
	context.setClassLoader(this.parent.getClassLoader());
}

This appears to fix the problem in my local testing.

I was able to replicate this issue in separate project. This project need service registry

./gradlew bootRun doesnt have this issue

but

./gradlew bootJar
and running java -jar build/libs/feign-0.0.1-SNAPSHOT.jar results in this problem when you invoke following url http://localhost:8080/hi

Environment

OpenJDK 11.0.2 Spring Boot: 2.1.2.RELEASE Greenwich.RELEASE

feign.zip

Unfortunately I’ve absolutely no idea what is that special at this µService (maybe except that we use dynamically created feign clients here). Anyway, I’ll spend a few hours this week to dig a bit deeper. I’ll keep you informed about my analysis.