Skip to content

ComponentScanBeanDefinitionParser::parseTypeFilters should not fail on ClassNotFoundException [SPR-16356] #20903

Closed
@spring-projects-issues

Description

@spring-projects-issues

Yanming Zhou opened SPR-16356 and commented

For example, parent project have such configuration to filter mvc and websocket component from root ApplicationContext, let them instantiated by child ApplicationContext

<context:component-scan base-package="com.acme">
     <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
     <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
     <context:exclude-filter type="assignable" expression="org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport"/>
     <context:exclude-filter type="assignable" expression="org.springframework.web.socket.config.annotation.WebSocketConfigurer"/>
</context:component-scan>

Some projects reuse such configuration and without spring-websocket dependency, it will throws ClassNotFoundException.

Caused by: java.lang.ClassNotFoundException: org.springframework.web.socket.config.annotation.WebSocketConfigurer
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333) ~[catalina.jar:8.0.44]
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167) ~[catalina.jar:8.0.44]
	at org.springframework.util.ClassUtils.forName(ClassUtils.java:255) ~[spring-core-5.0.2.jar:5.0.2.RELEASE]
	at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.createTypeFilter(ComponentScanBeanDefinitionParser.java:239) ~[spring-context-5.0.2.jar:5.0.2.RELEASE]
	at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parseTypeFilters(ComponentScanBeanDefinitionParser.java:215) ~[spring-context-5.0.2.jar:5.0.2.RELEASE]

I think spring should be lenient here, if class not present and the filter rule should ignore, at least "annotation" and "assignable" should do.


Affects: 4.3.13, 5.0.2

Referenced from: commits 092b3d4, 4adc820

Backported to: 4.3.14

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions