admin管理员组

文章数量:1221259

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.

本文标签: mavenIntelliJ CE run springboot App with external config fileStack Overflow