-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: bugA general bugA general bug
Milestone
Description
Tobias Mattsson opened SPR-10970 and commented
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:
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() {}
}
}
The test case:
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);
}
}
The beans XML file:
<?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>The test fails with:
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)
Its easily fixable of course by adding <bean class="FooController$BarController" /> but I still wanted to let you know.
Affects: 4.0 M3
Attachments:
- FooController.java (430 bytes)
- NestedControllerTest.java (509 bytes)
- NestedControllerTest-test.xml (596 bytes)
Issue Links:
- @Component within @Configuration class cannot @Autowire Regression [SPR-10865] #15492
@Componentwithin@Configurationclass cannot@AutowireRegression
Referenced from: commits 9bfbe36
0 votes, 5 watchers
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: bugA general bugA general bug