I created a simple project with one controller and instead of putting @RestController annotation on the controller class, I am creating it as a bean in the configuration class. It works in Spring Boot 2.7.10 (and older ones), but after migration to spring boot 3 (I checked it on 3.0.0 and 3.0.5 versions) I am getting 404. If I remove the bean from the configuration class and add @RestController annotation to controller class, everything works fine, but I would like to have the possibility to e.g. disable the controller from the configuration class level as I used to have.

Link to exemplary project: https://github.com/tomasz0801/spring-playground It contains one failing test, but if I switch Spring Boot version to 2.7.10 it passes.

Comment From: scottfrederick

The difference you're seeing between Spring Boot 2.7 and 3.0 is due to a change in Spring Framework. In Spring Framework 5, a @RequestMapping annotation was enough for Spring to consider the bean as a controller. With Spring Framework 6, a @Controller or @RestController annotation is required to consider the bean as a controller. See https://github.com/spring-projects/spring-framework/issues/22154#issuecomment-936906502 for the details.

To accomplish the level of configuration control that you want, you can add @RestController to the controller class and exclude it (or the entire package it is in) from component scanning.

Comment From: tomasz0801

Thank you for your detailed answer. I wasn't aware of that change