-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Cannot declare a Spring MVC controller with @Bean (without @Controller) since version 6 #29650
Comments
I think it relates to #28978 |
This change has been introduced in #22154. |
@bclozel I know it has been introduced in #22154. I read #22154 before creating this issue. Can you please re-open this issue? It would at least allow someone to tell me that |
Conditional controller declaration is still supported. Adding |
To test my boot starter library, I need to declare a class like this in my test directory: @SpringBootApplication
public class App {
public static void main(String[] args) {
new SpringApplication(App.class).run(args);
}
}
|
Moreover, from a usability POV, #22154 creates a difference between |
You need to organize your auto-configuration library and its testing support so that the auto-configuration packages are never scanned. This is called out in the Spring Boot reference documentation:
As for
This is an important behavior change and I understand that this is quite inconvenient for you, but considering all the related issues and reasons listed in #22154 I don't think we're going to change this behavior back. Especially since the case you're reporting is invalid in the first place, since you were using this behavior without knowing it to work around the fact that the package+scanning arrangement of your library is not ideal. You could very much run into another issue that's related to scanning there without having controllers involved. |
I am not asking for a revert. I think the notion of That way controllers would be declared like this by starter libraries: @RequestMappingController
@RequestMapping
class MyController {
} And like this for component scanning: @Controller
@RequestMappingController
@RequestMapping
class MyController {
} A meta anotation coupling |
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:
Now, because of
spring-framework/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java
Line 288 in 4f232a9
@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?
The text was updated successfully, but these errors were encountered: