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

Unresolvable class in 'basePackageClasses' annotation attribute results in misleading and hard to diagnose error [SPR-13177] #17769

spring-projects-issues opened this issue Jul 1, 2015 · 1 comment


Copy link

@spring-projects-issues spring-projects-issues commented Jul 1, 2015

Tim Reidel opened SPR-13177 and commented

I ran into an issue with my spring-based project that results in a hard-to diagnose error. Fortunately I also have the solution. :)

When starting my application using spring-boot I get the following exception trace:

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [ XXXXXXX ]; nested exception is java.lang.IllegalArgumentException: Attribute 'basePackageClasses' not found
        at org.springframework.context.annotation.ConfigurationClassParser.parse(
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(
        at org.springframework.boot.SpringApplication.refresh(
        at com.fancypants.common.application.Application.main(
Caused by: java.lang.IllegalArgumentException: Attribute 'basePackageClasses' not found
        at org.springframework.util.Assert.notNull(
        at org.springframework.core.annotation.AnnotationAttributes.doGet(
        at org.springframework.core.annotation.AnnotationAttributes.getClassArray(
        at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(
        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(
        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(
        at org.springframework.context.annotation.ConfigurationClassParser.parse(
        at org.springframework.context.annotation.ConfigurationClassParser.parse(
        ... 10 more

where XXXXXXX = one of my configuration classes.

basePackageClasses is certainly defined in the @ComponentScan annotation. It turns out that one of the classes referenced in basePackageClasses is not defined. The effect of this is that in AnnotationReadingVisitorUtils (which helps to parse the annotation) a ClassNotFoundException is thrown. This is expected and normal since my configuration was wrong and I was missing some jars in the classpath.

The ClassNotFoundException is caught by this piece of code in AnnotationReadingVisitorUtils:

catch (Exception ex) {
	// Class not found - can't resolve class reference in annotation
	// attribute.

Nothing is done with the error with the effect being that basePackageClasses is not defined in the resulting AnnotiationAttributes object. Later on when the AnnotationAttributes object is queried for the basePackageClasses they aren't found, resulting in the misleading error above.

My suggestion is to throw an IllegalArgumentException in the catch block above, indicating which class was not found. I can likely submit a pull request to this effect if needed.

Affects: 4.1.6

Referenced from: commits b7acddb

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 6, 2015

Juergen Hoeller commented

I'm resolving this for 4.2 only at this point, since the solution is somewhat involved, storing the Exception instances in AnnotationAttributes and re-throwing them on access. This is unfortunately necessary since we're scanning a lot of annotations across an application's codebase and generally want to be lenient about non-resolvable attributes that we do not care about. So re-throwing at access time only raises an error for attributes that we are actually trying to parse.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants