org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [FooController$BarController] is defined

Spring JIRA | Tobias Mattsson | 3 years ago
  1. 0

    When testing with M3 and BUILD-SNAPSHOT I've found a regression from previous versions. In one of my test cases I'm using annotated controllers that I define explicitly rather than classpath scanning for them. In previous versions of Spring nested classes annotated with @Controller, @Service, @Respository would be found but in 4.0 they're not. The controller class: {code} import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class FooController { @RequestMapping("/foo") public void foo() {} @Controller public static class BarController { @RequestMapping("/bar") public void bar() {} } } {code} The test case: {code} import org.junit.Test; import org.springframework.web.context.support.XmlWebApplicationContext; public class NestedControllerTest { @Test public void testFindsNestedController() { XmlWebApplicationContext wac = new XmlWebApplicationContext(); wac.setConfigLocation("classpath:NestedControllerTest-test.xml"); wac.refresh(); wac.getBean(FooController.class); // Fails in 4.0.0, works in 3.2.4 wac.getBean(FooController.BarController.class); } } {code} The beans XML file: {code:xml} <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config/> <bean class="FooController" /> </beans> {code} The test fails with: {noformat} org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [FooController$BarController] is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:318) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985) at NestedControllerTest.testFindsNestedController(NestedControllerTest.java:16) {noformat} Its easily fixable of course by adding <bean class="FooController$BarController" /> but I still wanted to let you know.

    Spring JIRA | 3 years ago | Tobias Mattsson
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [FooController$BarController] is defined
  2. 0

    When testing with M3 and BUILD-SNAPSHOT I've found a regression from previous versions. In one of my test cases I'm using annotated controllers that I define explicitly rather than classpath scanning for them. In previous versions of Spring nested classes annotated with @Controller, @Service, @Respository would be found but in 4.0 they're not. The controller class: {code} import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class FooController { @RequestMapping("/foo") public void foo() {} @Controller public static class BarController { @RequestMapping("/bar") public void bar() {} } } {code} The test case: {code} import org.junit.Test; import org.springframework.web.context.support.XmlWebApplicationContext; public class NestedControllerTest { @Test public void testFindsNestedController() { XmlWebApplicationContext wac = new XmlWebApplicationContext(); wac.setConfigLocation("classpath:NestedControllerTest-test.xml"); wac.refresh(); wac.getBean(FooController.class); // Fails in 4.0.0, works in 3.2.4 wac.getBean(FooController.BarController.class); } } {code} The beans XML file: {code:xml} <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config/> <bean class="FooController" /> </beans> {code} The test fails with: {noformat} org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [FooController$BarController] is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:318) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985) at NestedControllerTest.testFindsNestedController(NestedControllerTest.java:16) {noformat} Its easily fixable of course by adding <bean class="FooController$BarController" /> but I still wanted to let you know.

    Spring JIRA | 3 years ago | Tobias Mattsson
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [FooController$BarController] is defined
  3. 0

    NoSuchBeanDefinitionException with Spring and Hibernate

    Stack Overflow | 3 years ago | disable1992
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [core.HibernateSplitterDao] is defined
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    @EnableAspectJAutoProxy not work with proxyTargetClass=false

    Stack Overflow | 3 years ago | Dani
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.pjcom.springaop.message.impl.MessagePrinter] is defined
  6. 0

    Spring Dependency Injection - JournalDev

    journaldev.com | 6 months ago
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.sapmle.MyCommunication] is defined

  1. Gatgeagent 4 times, last 2 months ago
  2. Pilleo 6 times, last 2 months ago
  3. qavid 2 times, last 6 months ago
  4. MrMonkey 3 times, last 8 months ago
  5. Piz 2 times, last 4 months ago
2 more registered users
19 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. org.springframework.beans.factory.NoSuchBeanDefinitionException

    No qualifying bean of type [FooController$BarController] is defined

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean()
  2. Spring Beans
    DefaultListableBeanFactory.getBean
    1. org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:318)
    1 frame
  3. Spring Context
    AbstractApplicationContext.getBean
    1. org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)
    1 frame
  4. Unknown
    NestedControllerTest.testFindsNestedController
    1. NestedControllerTest.testFindsNestedController(NestedControllerTest.java:16)
    1 frame