ip696
ip696

Reputation: 7084

Spring boot starts even if start with nonexistent profile

I have spring boot application - server.jar with next structure:

-resources
 -application.yaml

After the build, I create a folder with a name source. And put my jar to this folder. Also, I create start .bat file

-source
 -server.jar
 -start.bat

In start.but the file I write next:

java -Dspring.profiles.active="foofoofoo" -jar server.jar
pause

When I run start.bat my server starts with log:

The following profiles are active: foofoofoo

And use properties from application.yaml. I have not profile with name foofoofoo and I have not apllication-foofoofoo.yaml. Why? Why spring writes that it loads foofoofoo profile, load application.yaml and work?

It must crash because I start the application with the nonexistent profile!

Instead, I see a running application with another property! How can I process this?

Upvotes: 2

Views: 1010

Answers (2)

htshame
htshame

Reputation: 7330

When you start the application application.yml file in your resources directory is getting included anyway.

If you also have application-yourProfileName.yml in resources directory and add

--spring.profile.active=yourProfileName parameter,

then both property files are getting included, and NOTE that in this case application-yourProfileName.yml override the same properties in application.yml.

Upvotes: 1

HTN
HTN

Reputation: 3594

The profile can be used in more ways than just application's properties. It does not matter if you do not have application-your-profile.{properties, yml}. Loading profile does not mean loading properties file.

Upvotes: 0

Related Questions