Skip to content

Regression with detecting nested components [SPR-10970] #15598

@spring-projects-issues

Description

@spring-projects-issues

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:

Issue Links:

Referenced from: commits 9bfbe36

0 votes, 5 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions