需要在 Spring 引导属性文件中使 AWS 区域可配置

Need to make AWS Regions configurable in Spring Boot properties file

现有代码:

public class AWSConfiguration
{
@Autowired
PropertyConfig property;

    public AmazonSQS getSqs()
    {
        return AmazonSQSClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(getBasicAWSCredentials()))
                .withRegion(Regions.US_WEST_2)
                .build();
    }
}

我想从属性文件中配置区域 说:在 application.properties 文件中

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();
    }