chi
08/24/2023, 5:26 AM@Configuration
annotated class that defines some beans, is it necessary that I @Import
it in the @SpringBootApplication
annotated class? If I don’t do this the beans aren’t available in the application context, but if I do they are loaded. Examples I find online doesn’t do this it seems
For example, I defined a configuration class that sets up various settings for OpenAPI, if I don’t @Import
this class in the main application class my beans don’t get used, but if I do they get used, however examples I saw online doesn’t do this.Riccardo Lippolis
08/24/2023, 6:00 AM@Configuration
class is defined.
The @SpringBootApplication
annotation is a meta-annotation for (among others) @ComponentScan
, which means it will search for Spring components in the current package and subpackages. If your config class is in one of these packages, it should be picked up automatically, and if not, you need to manually add it to the Spring configuration (or move it to a different package).chi
08/24/2023, 6:04 AM@ComponentScan
goes as far back as the root project and all classpaths defined from that scope and my main application class was in a different package. This was it 🙏