It is recommended that the main Spring Boot application class to be located in a root package above other classes so that the base "search package" to be the root one. All packages from the root will be scanned for configuration classes.
If you choose to place some other configuration classes in other packages, I believe these needs to be specified. For example, if you have your main application class in package "demo" and your Mongo configuration class in package "another.demo", the @ComponentScan
annotation for your main application class would need to look like:
@Configuration
@ComponentScan(basePackages={"another.demo", "demo"})
@EnableAutoConfiguration
public class Application {