I'm using @ConfigurationProperties
for auto configuration of properties. My code is working in IDE. But when I run the jar in command line, it is not working.
Configuration class:
@Configuration
@ConfigurationProperties(prefix="location")
public class Location {
private String base;
public String getBase() {
return base;
}
public void setBase(String base) {
this.base = base;
}
}
Main class:
@SpringBootApplication
@EnableConfigurationProperties(Location.class)
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
application.yml:
location:
base: c:\test
If I autowire
Location class, I see an instance created. But there is not property set. The code is not entering setBase()
method.
The application prints this in the console.
AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject'
annotation found and supported for autowiring
As nothing worked with yaml, I had to change to property file and use
@PropertySource({"classpath:application.properties"})
for the spring to identify the properties file