Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When configuration class parsing fails, provide more information about the class that triggered the failure #31146

Closed
wilkinsona opened this issue Aug 31, 2023 · 5 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@wilkinsona
Copy link
Member

Affects: 5.3 and later

See spring-projects/spring-boot#37153 for some background. In this case parsing has failed because a configuration class extends a class that doesn't exist. While the offending class can probably be identified using a debugger, it would be helpful if more information was included in the log message. In this case, the fully qualified name of the configuration class whose super-class is being processed would pinpoint the problem.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 31, 2023
@bclozel bclozel added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 31, 2023
@bclozel bclozel added this to the 6.1.x milestone Aug 31, 2023
@snicoll
Copy link
Member

snicoll commented Oct 24, 2023

Looking at the related issue, the root exception message seems to be:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class 

However, I don't see how this would be possible as the error message has additional brackets with the bean class name for a very long time.

throw new BeanDefinitionStoreException(
"Failed to parse configuration class [" + bd.getBeanClassName() + "]", ex);

I wonder if the OP in the boot issue hasn't tempered the exception message.

@snicoll
Copy link
Member

snicoll commented Oct 24, 2023

I have reproduced the problem and I can confirm that there is a class name. However, it is not the right class name:


org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.example.demo23upgrade.Demo23UpgradeApplication]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.class] cannot be opened because it does not exist
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:188) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:748) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.17.jar!/:2.7.17]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-2.7.17.jar!/:2.7.17]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:409) ~[spring-boot-2.7.17.jar!/:2.7.17]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.17.jar!/:2.7.17]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) ~[spring-boot-2.7.17.jar!/:2.7.17]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1289) ~[spring-boot-2.7.17.jar!/:2.7.17]
	at com.example.demo23upgrade.Demo23UpgradeApplication.main(Demo23UpgradeApplication.java:10) ~[classes!/:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[demo-23-upgrade-0.0.1-SNAPSHOT.jar:na]
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[demo-23-upgrade-0.0.1-SNAPSHOT.jar:na]
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[demo-23-upgrade-0.0.1-SNAPSHOT.jar:na]
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[demo-23-upgrade-0.0.1-SNAPSHOT.jar:na]
Caused by: java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.class] cannot be opened because it does not exist
	at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:203) ~[spring-core-5.3.30.jar!/:5.3.30]
	at org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:55) ~[spring-core-5.3.30.jar!/:5.3.30]
	at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:48) ~[spring-core-5.3.30.jar!/:5.3.30]
	at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103) ~[spring-core-5.3.30.jar!/:5.3.30]
	at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:86) ~[spring-boot-2.7.17.jar!/:2.7.17]
	at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:73) ~[spring-boot-2.7.17.jar!/:2.7.17]
	at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81) ~[spring-core-5.3.30.jar!/:5.3.30]
	at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:699) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getSuperClass(ConfigurationClassParser.java:1013) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:340) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:303) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:206) ~[spring-context-5.3.30.jar!/:5.3.30]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:174) ~[spring-context-5.3.30.jar!/:5.3.30]
	... 21 common frames omitted

It should be TestConfiguration that is defined as follows:

@Configuration
public class TestConfiguration extends WebSecurityConfigurerAdapter { }

@snicoll snicoll self-assigned this Oct 24, 2023
@snicoll snicoll modified the milestones: 6.1.x, 6.1.0-RC2 Oct 24, 2023
@snicoll
Copy link
Member

snicoll commented Oct 24, 2023

The revised exception message now looks as follows:

org.springframework.beans.factory.BeanDefinitionStoreException: I/O failure while processing configuration class [com.example.demo23upgrade.TestConfiguration]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:250) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:188) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:304) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:196) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:164) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:415) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:288) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:349) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:118) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:775) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:597) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:748) ~[spring-boot-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:450) ~[spring-boot-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) ~[spring-boot-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1336) ~[spring-boot-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1325) ~[spring-boot-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
	at com.example.demo23upgrade.Demo23UpgradeApplication.main(Demo23UpgradeApplication.java:10) ~[main/:na]
Caused by: java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.class] cannot be opened because it does not exist
	at org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:54) ~[spring-core-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:48) ~[spring-core-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103) ~[spring-core-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:86) ~[spring-boot-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
	at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:73) ~[spring-boot-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
	at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81) ~[spring-core-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:620) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getSuperClass(ConfigurationClassParser.java:933) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:341) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-6.1.0-SNAPSHOT.jar:6.1.0-SNAPSHOT]
	... 17 common frames omitted

@sedhha

This comment was marked as off-topic.

@snicoll

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants