javaspring-bootmicroservices

Spring boot inherit application.properties file to another application.properties file


I have two values in my parent project's application.properties file. jwt secret key and jwt issuer. I need to access those values from two different modules which are my microservices. image One of them is auth-service, other one is gateway. I am trying to get those values like;

    @Value("${security.jwt.secret-key}")
    private String jwtSecretKey;

    @Value("${security.jwt.issuer}")
    private String jwtIssuer;

But of course I dont have those values in my module's application properties file. Is there any way to manage that values from parent project's application file and inherit them from modules ?

I tried this code samples in my child's application properties but it didnt work.

spring.config.location=classpath:/application.properties
spring.config.additional-location=file:/Users/FF/Desktop/E-Commerce/src/main/resources/application.properties

Solution

  • I would suggest using an .env file where you can store your secrets (keys, passwords...). Then inside the constructor of your class, assign values retrieved from this file (.env) to the field using something like the java-dotenv dependency.