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

Failed to parse configuration class when using @ComponentScan with FilterType.ASPECTJ, without org.aspectj library. #34135

Closed
jbw9964 opened this issue Dec 21, 2024 · 1 comment
Labels
status: invalid An issue that we don't feel is valid

Comments

@jbw9964
Copy link

jbw9964 commented Dec 21, 2024

Hello, I'm using spring boot 3.4.0.

I've found that something goes wrong when using @ComponentScan in certain situations.

If I try to use excludeFilters on @ComponentScan with FilterType.ASPECTJ, application run fails.

@Configuration
@ComponentScan(
        excludeFilters = @Filter(type = FilterType.ASPECTJ, pattern = "*..SomeClass")
)
public class TestConfig {}
2024-12-21T20:08:37.465+09:00  WARN 20555 --- [app] [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [sections.App]
2024-12-21T20:08:37.573+09:00 ERROR 20555 --- [app] [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [sections.App]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:185) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:418) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:290) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:349) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:118) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:791) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:609) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.4.0.jar:3.4.0]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) ~[spring-boot-3.4.0.jar:3.4.0]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[spring-boot-3.4.0.jar:3.4.0]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:318) ~[spring-boot-3.4.0.jar:3.4.0]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361) ~[spring-boot-3.4.0.jar:3.4.0]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350) ~[spring-boot-3.4.0.jar:3.4.0]
	at sections.App.main(App.java:10) ~[main/:na]
Caused by: java.lang.NoClassDefFoundError: org/aspectj/weaver/World
	at org.springframework.context.annotation.TypeFilterUtils.createTypeFiltersFor(TypeFilterUtils.java:103) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:96) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:332) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:267) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:205) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:340) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:267) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:193) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:171) ~[spring-context-6.2.0.jar:6.2.0]
	... 13 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.World
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[na:na]
	... 22 common frames omitted


Process finished with exit code 1

However, If I add spring-starter-aop dependency (or aspectj library), application runs successfully, even the source code hasn't changed at all.

// build.gradle

dependencies {
    /* ... */

    implementation 'org.springframework.boot:spring-boot-starter-aop'
}

I think it's caused by AspectJTypeFilter on org.springframework.core.type.filter package.

If FilterType.ASPECTJ were used, TypeFilterUtils attempts to create AspectJTypeFilter.

But in AspectJTypeFilter, it requires World, TypePattern, etc of org.aspectj library, so it cause error.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 21, 2024
@snicoll
Copy link
Member

snicoll commented Dec 23, 2024

This is working as designed. You are opting-in for an AspectJ feature (as you found out yourself) so AspectJ must be on the classpath to use this.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2024
@snicoll snicoll added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants