现有代码:
public class AWSConfiguration
{
@Autowired
PropertyConfig property;
public AmazonSQS getSqs()
{
return AmazonSQSClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(getBasicAWSCredentials()))
.withRegion(Regions.US_WEST_2)
.build();
}
}
我想从属性文件配置区域 说:在应用程序属性文件中
awsRegion=us-west-2
并在现有代码中使用此属性
public AmazonSQS getSqs()
{
return AmazonSQSClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(getBasicAWSCredentials()))
.withRegion({fetch from property file})
.build();
}
在解决方案中找到
@Value("${doormls.awsRegion}")
private String regionSQS;
public AmazonSQS getSqs()
{
return AmazonSQSClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(getBasicAWSCredentials()))
.withRegion(Regions.fromName(regionSQS))
.build();
}