I am running my application with Spring Boot (1.2.0.RELEASE) using the @SpringBootApplication annotation.
What I try to achieve is to have the following without using long prefixes in each @Value annotation:
application.properties
prefix.key1=value1
prefix.key2=value2
DefaultService.java
@Service
@ConfigurationProperties("prefix")
public class DefaultService implements Service {
private final String key1;
private final String key2;
@Autowired
public DefaultService(@Value("${key1}") final String key1, @Value("${key2}") final String key2) {
this.key1 = key1;
this.key2 = key2;
}
}
I know that this can be done without using @Value and in need of setters (@ConfigurationProperties prefix not working) or with http://docs.spring.io/spring-boot/docs/1.2.0.RELEASE/reference/htmlsingle/#boot-features-external-config-typesafe-configuration-properties but I try to achieve it in the constructor.