Skip to content

@Enable* should be supported without @Configuration [SPR-10660] #15288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Jun 17, 2013 · 7 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jun 17, 2013

Rob Winch opened SPR-10660 and commented

@Enable annotations have no meaning unless combined with @Configuration. It would be useful to allow configurations with only @Enable annotations.

It would be ideal if all the following tests pass (each test is marked with a comment with its current behavior):

package sample;

... imports omitted ...

public class EnableWithNoConfigurationAnnotationTests {
    private ConfigurableApplicationContext context;

    @After
    public void closeContext() {
        if(context != null) {
            context.close();
        }
    }

    // succeeds
    @Test
    public void enableWebMvcWithConfigurationAnnotation() {
        assertLoadsWebMvc(EnableWebMvcWithConfigurationAnnotationConfig.class);
    }

    @EnableWebMvc
    @Configuration
    static class EnableWebMvcWithConfigurationAnnotationConfig {}

    // fails
    @Test
    public void enableWebMvcNoConfigurationAnnotation() {
        assertLoadsWebMvc(EnableWebMvcNoConfigurationAnnotationConfig.class);
    }

    @EnableWebMvc
    static class EnableWebMvcNoConfigurationAnnotationConfig {}

    // fails
    @Test
    public void enableWebMvcNoConfigurationClasspathScanning() {
        assertLoadsWebMvc(EnableWebMvcWithClasspathScanningConfig.class);
    }

    @Configuration
    @ComponentScan(basePackageClasses=ScannedEnableWebMvcNoConfigurationAnnotationConfig.class)
    static class EnableWebMvcWithClasspathScanningConfig {}

    private void assertLoadsWebMvc(Class<?>... configs) {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.setServletConfig(new MockServletConfig());
        context.setServletContext(new MockServletContext());
        context.register(configs);
        context.refresh();
        context.start();

        // verify RequestMappingHandlerMapping is found
        context.getBean(RequestMappingHandlerMapping.class);

        this.context = context;
    }
}
package package sample.scanning;

... imports omitted...

@EnableWebMvc
public class ScannedEnableWebMvcNoConfigurationAnnotationConfig {

}

Issue Links:

Referenced from: commits d18b3f0

@spring-projects-issues
Copy link
Collaborator Author

Rob Winch commented

Juergen Hoeller Any chance we could look into this for the next release?

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jan 20, 2016

Juergen Hoeller commented

Rob Winch, this effectively duplicates #15163... and therefore works since 4.0 already. Have you been trying this against 3.2.x?

@spring-projects-issues
Copy link
Collaborator Author

Rob Winch commented

Thanks Juergen Hoeller! I hadn't realized it was fixed as part of another issue. I was bumping the issue due to some feedback on StackOverflow. I responded to the comment that this should be resolved and am awaiting any response. Thanks again!

@spring-projects-issues
Copy link
Collaborator Author

Rob Winch commented

Juergen Hoeller I just noticed that this was not actually resolved completely. The enableWebMvcNoConfigurationClasspathScanning still fails.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I'm afraid this works as designed: Classpath scanning requires a match for an include filter, by default one of our @Component derived stereotypes. Since @EnableWebMvc on its own does not constitute such a stereotype, scanning indeed only works with an @Configuration (or any other @Component) declaration next to it, in contrast to an explicitly registered component where no such identification by stereotype is required.

@spring-projects-issues
Copy link
Collaborator Author

Rob Winch commented

Juergen Hoeller Thanks for the response. Does it make sense to explicitly add @Component to @Enable* annotations?

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I'm afraid it doesn't.. those are really orthogonal concerns. Through custom include/exclude filters, people may already selectively pick up certain component classes but not others, and we'd arguably mess that up if the plain presence of @Enable annotations all of a sudden indicates a component nature for such scanning purposes.

@spring-projects-issues spring-projects-issues added status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants