0

I have generated a jhipster monolithic app. I have created a class to connect with the AWS S3 and upload a file there. I defined the properties in .yml file. Here everything works fine.

When I am trying to run the provided tests, most of them are failing with the following error:

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

S3AutoConfig is the class which uses the properties. I checked jhipster's documenation and several posts, like the one below: Adding applicationproperties in Jhipster

which mention that you should provide the properties in the ApplicationProperties class (seems a bit redundant).

I defined the properties also in the java class, but the tests are still failing with the same error above.

How should I define the properties, so they are picked up by the tests? Is it necessary to provide them also in the java class as some posts suggest?

properties

szark
  • 77
  • 10

1 Answers1

1

Your implementation cannot work because you are defining Aws class within ApplicationProperties which means that your AWS properties will be prefixed by application, so for example application.aws.endpoint.url which does not match your application*.yml structure and this is why you get this error.

You should extract Aws class and its inner classes to its own file (Aws.java) and use prefix "aws". Also, it would probably better named as AwsProperties.

@ConfigurationProperties(prefix = "aws", ignoreUnknownFields = false)
public class Aws {

Then the second point about tests is that they are using a different classpath than main class so you should ensure that you define these properties also in src/test/resources/config/application.yml

Gaël Marziou
  • 16,028
  • 4
  • 38
  • 49
  • Thank you Gaël! Yes, shame on me, I was expecting that tests would have their own separate .yml file but I somehow did not see it, thanks for the explanation, tests are working fine again :) – szark Oct 27 '20 at 06:32