Reputation: 95
I extended my JHipster application and wrote a service class with the following code:
@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);
}
my application-dev.yml includes the following:
amazonProperties:
endpointUrl: https://s3.eu-central-1.amazonaws.com
accessKey: XYZ
secretKey: XYZ
bucketName: XYZ
When I start my application with mvwn everything works. When I run my tests I get the following Exception:
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}"
Upvotes: 0
Views: 1294
Reputation: 10110
Since you are using jhipster, this happens because you put the credentials in application-dev.yml, and this file will be visible only in dev profile
You need to put in the application.yml
file under the src/main/test/resources
folder. The test runner will look for properties in this file.
Upvotes: 5