Springboot not loading application.dev.properties file

前端 未结 4 2201
-上瘾入骨i
-上瘾入骨i 2021-02-19 18:27

In my project I want to use environment specific property file. For example if I am running it into development it should use application.dev.properties, for production it shoul

相关标签:
4条回答
  • 2021-02-19 19:10

    Try adding a vm argument in the run configuration:

    -Dspring.profiles.active=dev
    
    0 讨论(0)
  • 2021-02-19 19:12

    If running on Eclipse or STS, then use following steps:

    1. Right click on project -> Run As -> Run Configuration.

    2. In the new window, select spring boot application on left side, and add details on the right and in the profile dropdown, select dev.

    3. Click apply and run.

    0 讨论(0)
  • 2021-02-19 19:13

    A few issues I noticed:

    1. @Value property name should be a String like @Value("${server.database.host}")
    2. Profile specific property files should follow application-{profile}.properties format, e.g. application-dev.properties
    3. Try passing the profile with -D like java -Dspring.profiles.active=dev -jar app.jar
    0 讨论(0)
  • 2021-02-19 19:23

    You are supposed to specify which profile to run with as follows:

    mvn spring-boot:run -Dspring-boot.run.profiles=foo,bar
    

    Also see documentation: https://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-profiles.html

    0 讨论(0)
提交回复
热议问题