Questions tagged [spring-profiles]

Spring Profiles provide a way to segregate parts of an application configuration and make it only available in certain environments.

Spring Profiles provide a way to segregate parts of an application configuration and make it only available in certain environments.

http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html

349 questions
249
votes
8 answers

How do you get current active/default Environment profile programmatically in Spring?

I need to code different logic based on different current Environment profile. How can you get the currently active and default profiles from Spring?
Bobo
  • 8,777
  • 18
  • 66
  • 85
130
votes
8 answers

How to set Spring profile from system variable?

I have a Spring project which uses another project. Each project has its own spring profile initialize from java code using applicationContext.xml and *.properties for each profile. I inject the profile from args[]. The problem is that second…
user2656851
  • 1,643
  • 4
  • 12
  • 15
88
votes
6 answers

Setting Spring Profile variable

I have two Spring profiles: dev and test. I want to set the active profile in the server environment, I don't want to set it in my code so that wherever I deploy my application the profile gets loaded based on the profile in the server. How can I…
Maheshwaran K
  • 1,982
  • 5
  • 19
  • 22
84
votes
5 answers

How to disable flyway in a particular Spring profile?

Now I have a spring-boot app which uses MsSQL server. And we use flyway for migrations. I want to add an additional profile for tests. I want to generate tables from entity classes instead of using flyway. I tried smth to write like this in…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
75
votes
1 answer

Including bean definition when a profile is NOT active

In my application I use several profiles to make certain beans eligible for autowiring. What I'm missing is the possibility to make a bean eligible for autowiring when a certain profile is NOT active. The best way of doing it that I thought about…
ShyJ
  • 4,560
  • 1
  • 19
  • 19
73
votes
8 answers

How to set spring active profiles with maven profiles

I have an application with maven as a build tool. I am using maven profiles to set up different properties from different profiles. What i would like to do is that all active profiles in maven will be ported to spring active profiles as well so i…
Gleeb
  • 10,773
  • 26
  • 92
  • 135
70
votes
4 answers

What is the order of precedence when there are multiple Spring's environment profiles as set by spring.profiles.active

I am just wondering what the order of precedence is when multiple Spring active profiles have been specified. Say I want the default profile to be active but the dev profile to override it when there are several identical elements (beans for…
balteo
  • 23,602
  • 63
  • 219
  • 412
64
votes
14 answers

SpringBoot: Unable to find a single main class from the following candidates

I've generated a Spring Boot web application using Spring Initializer, embedded Tomcat, Thymeleaf template engine.Technologies used: Spring Boot 1.4.2.RELEASE, Spring 4.3.4.RELEASE, Thymeleaf 2.1.5.RELEASE, Tomcat Embed 8.5.6, Maven 3, Java 8 I have…
Nuñito Calzada
  • 4,394
  • 47
  • 174
  • 301
53
votes
8 answers

Spring Profiles on method level?

I'd like to introduce some methods that are only executed during development. I thought I might use Spring @Profile annotation here? But how can I apply this annotation on class level, so that this method is only invoked if the specific profile is…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
50
votes
7 answers

Spring: How to do AND in Profiles?

Spring Profile annotation allows you to select profiles. However if you read documentation it only allows you to select more than one profile with OR operation. If you specify @Profile("A", "B") then your bean will be up if either profile A or…
Artem
  • 7,275
  • 15
  • 57
  • 97
45
votes
4 answers

Including profiles in spring boot 2.4.0 version

As a developer, I use the default dev profile in my local development environment. Here is part of my application-dev.properties file: # Profiles spring.profiles.include=auth Previously I used Spring Boot 2.3.0.RELEASE and the…
misnomer42
  • 579
  • 1
  • 5
  • 10
31
votes
5 answers

Spring "spring.profiles.include" overrides

My intention is to have two profiles in a spring boot application - development and production one. Development profile is meant just to override some variables of production profile (like in-memory database instead of database in the cloud). As I…
Daniel Szymatowicz
  • 435
  • 1
  • 4
  • 7
28
votes
4 answers

Spring Boot Configuration skip registration on multiple @Profile

I've a Spring Boot application with different Profile setup : dev, prod, qc, console etc. The two configuration classes are setup as follows. MyConfigurationA should be registered for all profiles except console. MyConfigurationB should be…
gtiwari333
  • 24,554
  • 15
  • 75
  • 102
24
votes
3 answers

How do you properly set different Spring profiles in bootstrap file (for Spring Boot to target different Cloud Config Servers)?

We have different config servers per environment. Each spring boot application should target its corresponding config server. I have tried to achieve this by setting profiles in the bootstrap.properties file,…
dev_feed
  • 689
  • 2
  • 7
  • 25
24
votes
6 answers

Spring Boot Programmatically setting profiles

How to set active profile in spring boot Application. This application will be deployed in stand alone Tomcat. I have 2 property files application-{profile}.properties. My Application class @SpringBootApplication public class…
Mukun
  • 1,756
  • 10
  • 30
  • 57
1
2 3
23 24