I have a problem with spring boot when using autowired on a configuration class. I have minimized the problem by creating a small spring boot project on github.
I created the MyBean class declaring it as @Component and attempting the autowired of the MyConf class which is declared as @Configuration (and reads the property in the file myconfig.properties). In theory, everything is in the spring context, but when the application starts myConfigProp variable in MyBean is null.
Where am I wrong?
I also tried the following solutions, all not working:
- Insert the @DependsOn in MyBean
- Commented on the @Component and configured MyBean as @Bean of spring
The last test I did (not present on github project) was to pass MyConfigProp as a parameter in MyBean constructor, and it worked.
@Component
public class MyBean {
String message;
public MyBean(MyConfigProp myConfigProp) {
this.message = myConfigProp.getMessage();
}
}
I am somewhat confused.