Skip to content

Cannot declare a Spring MVC controller with @Bean (without @Controller) since version 6 #29650

Closed as not planned
@reda-alaoui

Description

@reda-alaoui

Affects: 6.0.2

Since #22154 , it seems not possible anymore to declare a Controller class via an @Bean method.

Before we could do that:

@RequestMapping
class MyController {

}

@ConditionalOnSomething
@AutoConfiguration
class MyConfiguration {

  @Bean
  public MyController myController() {
     return new MyController();
  }
}

Now, because of

, the controller is not considered as a request mapping handler because it is missing @Controller .

But annotating it make it discoverable by component scan (enabled by the test classes for example), which prevents us from declaring the component conditionally.

Is there something I am missing here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions