Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-16356

ComponentScanBeanDefinitionParser::parseTypeFilters should not fail on ClassNotFoundException

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Complete
    • 4.3.13, 5.0.2
    • 4.3.14, 5.0.3
    • Core
    • None
    • true

    Description

      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.

      Attachments

        Activity

          People

            juergen.hoeller Juergen Hoeller
            quaff Yanming Zhou
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              3 years, 38 weeks, 1 day ago