JHipster无法解析占位符

时间:2018-09-18 20:59:19

标签: spring jhipster

我扩展了JHipster应用程序,并使用以下代码编写了服务类:

@Component
@Transactional
public class AmazonClient {

private AmazonS3 s3Client;

@Value("${amazonProperties.endpointUrl}")
private String endpointUrl;

@Value("${amazonProperties.bucketName}")
private String bucketName;

@Value("${amazonProperties.accessKey}")
private String accessKey;

@Value("${amazonProperties.secretKey}")
private String secretKey;

public AmazonClient() {

}

@PostConstruct
private void initializeAmazon() {
    AWSCredentials credentials = new BasicAWSCredentials(this.accessKey, this.secretKey);
    this.s3Client = new AmazonS3Client(credentials);
}

我的application-dev.yml包括以下内容:

amazonProperties:
  endpointUrl: https://s3.eu-central-1.amazonaws.com
  accessKey: XYZ
  secretKey: XYZ
  bucketName: XYZ

当我使用mvwn启动应用程序时,一切正常。运行测试时,出现以下异常:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'amazonClient': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'amazonProperties.endpointUrl' in value "${amazonProperties.endpointUrl}"

1 个答案:

答案 0 :(得分:4)

由于您使用的是jhipster,因此发生这种情况是因为您将凭据放在application-dev.yml中,并且该文件仅在开发配置文件中可见

您需要将application.yml文件夹下的src/main/test/resources文件放入。测试运行器将在此文件中查找属性。