Mukund Toshniwal
Mukund Toshniwal

Reputation: 3

Boot picking up property file from dependency instead of application

I am using spring boot and I have added another spring boot app as Maven dependency in my project. The problem I am facing is that when I run the application, it picks the property file of the dependency instead of my current application. For example if I run the app using dev profile, application-dev.property file is picked from dependency instead of the running application. I tried to debug the EnableEncryptablePropertySourcesPostProcessor file and below is the screenshot of the list of property file picked.

enter image description here

Upvotes: 0

Views: 3385

Answers (3)

Jaishant Biradar
Jaishant Biradar

Reputation: 61

**In Application.java file it should be something like this

@PropertySource("classpath:application.properties")

Upvotes: 0

Ravindra Devadiga
Ravindra Devadiga

Reputation: 692

Use PropertySource annotation to refer the properties file in your main application file as shown below

@PropertySource(value = { "file:/path/to/folder/file.properties" })

If you have same property in the multiple properties file then one in the classpath will get more preference

Upvotes: 1

Ulises
Ulises

Reputation: 9635

Check this out but you have a few options:

  1. Simply specify the config file name:

    java -jar myproject.jar --spring.config.name=myproject

And basically you can have myproject-dev.properties

  1. Or directly specify the config files you wanna import:

    java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties

Upvotes: 1

Related Questions