Reputation: 1042
I want to create a class using new operator and in that class I want to read a property from application.yml file, how to do that in Spring Boot application ?
In other words I cannot use @Value, @Autowire, @Component annotations.
Upvotes: 1
Views: 1186
Reputation: 116
You need to do something like this:
@Configuration
@ConfigurationProperties(prefix = "test")
public class TestProperties{
private String testProperty1;
public String getTestProperty1() {
return testProperty1;
}
public void setTestProperty1(String testProperty1) {
this.testProperty1= testProperty1;
}
}
next in Your application.properties:
test.testPropety1 = yourProperty
You can implement this properties class as bean because of @Configuration annotation. Hope that helps in Your problem :)
Upvotes: 1