O
O
Orkhan Hasanli2018-11-13 23:06:46
Java
Orkhan Hasanli, 2018-11-13 23:06:46

How to understand Spring profiles?

Hello!
Quite a strange situation with profiles in Spring Boot. Checked in versions 2.0.6 and 2.1.0
It is possible that I misunderstood the principle of how profiles work... I built
a project on Spring Boot ( https://start.spring.io/) via intelllij IDEA Ultimate Edition + using Gradle.
Created 3 .properties files

application.properties
application-dev.properties
application-production.properties

In the main application.properties file I wrote:
spring.profiles.active=dev
Accordingly, I added
server.port=7777 to the application-dev.properties file
1) I start the project and it ignores my configuration and starts on 8080.
2) I tried to register an active profile through the IDE. Edit Configuration -> Active Profiles -> dev (in Intellij there is no need to specify -DSpring...) I
run the project and again it starts at 8080 instead of 7777.
Only if I write the configuration in the main file, it will work.
3) Tried in Application.class via IDE "change profiles" and selected development, same result.
4) I tried to create a separate configuration file for the database and added @Profile("dev") and @Profile("production") to different methods.
At the same time, both methods are worked out ...
Where am I wrong? I watched a bunch of videos and surfed different sites.
PS I did the same manipulations with the yaml file, and also tried the project through the maven.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2018-12-28
@azerphoenix

Thanks to the help, I finally figured out the problem and it was terribly banal)))
In general, when creating a properties file, you must manually add .properties, if you select the properties file type in the IDE, it will simply create a file (not in the properties format.)
Solution link:
Why does Spring ignore profile file properties configurations?
Screen:
5c267edd6fce3692227363.png

R
Ruslan Lopatin, 2018-11-14
@lorus

Where are these files? They must be either in the class path or in the working directory (for IDEA, this is the default project root).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question