最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

maven - IntelliJ CE run spring-boot App with external config file - Stack Overflow

programmeradmin0浏览0评论

I must switch from Eclipse to IntelliJ 2024.3.1.1 upon customer's request. They use jdk1.8.0_271, SprinBoot 2.6.14 and they have a lot of Maven profile, one per customer, in their parent pom.

By the way for each Maven profile there are one or more Spring profile and one or more .properties file with configuration about datasource, path ecc...

In my Eclipse IDE I usually run the application from the boot-dashboard referencing external .properties file using the follow directive in JVM Option:

-Dspring.config.location=file:/path-to-properties-folder/, file:/path-to-file/application.properties

As you know the above directive overwrite the default Spring configuration. I also usually mix the default config adding some other file using spring.config.additional-location instead of the one mentioned above.

The question is how can I do the same with IntelliJ? I have tryed to link a .properties file this way:

(Ignore the JAVA 21 Version this is just an example)

I have tried using spring-boot:run instead of spring-boot:start, I have also used different way to achieve the file like:

-Dspring.config.location=file:/path-to-folder/                       --> should read everything inside the folder
-Dspring.config.location=file:/path-to-file/application.properties

Both two inserted in VM Options field of Maven Run/Debug Configuration but it never worked. What's wrong?

I must switch from Eclipse to IntelliJ 2024.3.1.1 upon customer's request. They use jdk1.8.0_271, SprinBoot 2.6.14 and they have a lot of Maven profile, one per customer, in their parent pom.

By the way for each Maven profile there are one or more Spring profile and one or more .properties file with configuration about datasource, path ecc...

In my Eclipse IDE I usually run the application from the boot-dashboard referencing external .properties file using the follow directive in JVM Option:

-Dspring.config.location=file:/path-to-properties-folder/, file:/path-to-file/application.properties

As you know the above directive overwrite the default Spring configuration. I also usually mix the default config adding some other file using spring.config.additional-location instead of the one mentioned above.

The question is how can I do the same with IntelliJ? I have tryed to link a .properties file this way:

(Ignore the JAVA 21 Version this is just an example)

I have tried using spring-boot:run instead of spring-boot:start, I have also used different way to achieve the file like:

-Dspring.config.location=file:/path-to-folder/                       --> should read everything inside the folder
-Dspring.config.location=file:/path-to-file/application.properties

Both two inserted in VM Options field of Maven Run/Debug Configuration but it never worked. What's wrong?

Share Improve this question asked Feb 6 at 20:38 CoderJammerCoderJammer 7154 gold badges11 silver badges38 bronze badges 2
  • In your yml file, add spring: profiles: active: native. Create application-native.yml then define location of your configuration folder here.| spring: config: import: <your-config-folder> docs.spring.io/spring-boot/docs/2.6.14/reference/html/… – Syed Commented Feb 7 at 3:57
  • thanks for your reply man but this is a workaround not the solution I'm looking for... and you read the wrong paragraph of the docs, the 2.3 is the right one. Read my answer below – CoderJammer Commented Feb 7 at 11:30
Add a comment  | 

1 Answer 1

Reset to default 0

Using the same directive in the Environment Varaible work like a sharm:

Hope helps.

发布评论

评论列表(0)

  1. 暂无评论