Reputation: 306
Existing Code :
public class AWSConfiguration
{
@Autowired
PropertyConfig property;
public AmazonSQS getSqs()
{
return AmazonSQSClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(getBasicAWSCredentials()))
.withRegion(Regions.US_WEST_2)
.build();
}
}
I want to make Regions Configured From Properties File Say : In application.properties file
awsRegion=us-west-2
and Use this property in existing code
public AmazonSQS getSqs()
{
return AmazonSQSClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(getBasicAWSCredentials()))
.withRegion({fetch from property file})
.build();
}
Upvotes: 0
Views: 551
Reputation: 306
Found below solution
@Value("${doormls.awsRegion}")
private String regionSQS;
public AmazonSQS getSqs()
{
return AmazonSQSClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(getBasicAWSCredentials()))
.withRegion(Regions.fromName(regionSQS))
.build();
}
Upvotes: 1