简体   繁体   中英

jhipster java tests failing - application properties

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?

特性

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM