This is my project package structure.
org.myApp
MainApplication.java
org.myApp.controller
org.myApp.repositories
org.myApp.utils
I have a @SpringBootApplication placed in my org.myApp.MainApplication class and I'm expecting that it will scan all my subpackages for components as they are placed in the same package as this main class.
However, I have created this new class in org.myApp.utils called Utils which is not being picked up by the application context.
package org.myApp.utils;
import java.util.Properties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
@Configuration
public class Utils {
Utils() throws IOException{
getAllProps();
}
@Bean
public static Properties getAllProps() throws IOException{
return new Properties();
}
}
The class is only scanned when I explicitly use a @ComponentScan("org.myApp.Utils") in my MainApplication.java class however this breaks the rest of my application for some reason.
How do I ensure that my Utils class is scanned and placed in the application context?