My question was already asked by someone else and had an answer 11 years ago here:
How can I inject a property value into a Spring Bean which was configured using annotations?
That was 2008. It is now 2019 and my code still looks like this:
@Configuration
public class Config {
private @Value("${region}") String region;
private @Value("${bucket}") String bucket;
@Bean
AwsS3Template getAwsS3Template() {
AwsS3Template s3 = new AwsS3Template();
s3.setRegion(region);
s3.setBucket(bucket);
return s3;
}
}
Is there now a way to do this fully declaratively?
I would like to write something like this:
@Configuration
public class Config {
@Bean
@AutoApplyPropertyValues /* pseudo-code, no such annotation exists */
AwsS3Template getAwsS3Template() {
return new AwsS3Template();
}
}