spring-profiles

Modify active profiles and refresh ApplicationContext runtime in a Spring Boot application

微笑、不失礼 提交于 2019-11-29 10:10:57
I have a Spring boot Web application. The application is configured via java classes using the @Configurable annotation. I have introduced two profiles: 'install', 'normal'. If the install profile is active, none of the Beans that require DB connection is loaded. I want to create a controller where the user can set up the db connection parameters and When it's done I want to switch the active profile from 'install' to 'normal' and refresh the application context, so the Spring can init every bean that needs DB data source. I can modify the list of active profiles from code, without problems,

Spring Boot Programmatically setting profiles

核能气质少年 提交于 2019-11-28 23:46:31
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 Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } public static void main(String[] args) { System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "dev"); ApplicationContext ctx = SpringApplication.run(Application

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

China☆狼群 提交于 2019-11-28 20:28:51
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 instance) to choose from but with different profiles... Say for instance I have two PropertySourcesPlaceholderConfigurer beans configured with "default" and "dev" values a environment profiles. If I use the following profile activation: -Dspring.profiles.active="default,dev" Will the dev profile override the default one? If not how can the above behavior

How to set Spring profile from system variable?

痴心易碎 提交于 2019-11-28 20:05:09
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 project uses the default configuration for the env from the applicationContext.xml I can not inject the env from args[] to the second project and I tried looking for an article which will explain how Spring profile works. Is there a hierarchy on which it will look the profile when default is not configured at applicationContext.xml ? Is System var

Setting Spring Profile variable

◇◆丶佛笑我妖孽 提交于 2019-11-28 16:25:12
问题 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 do that? 回答1: You can simply set a system property on the server as follows... -Dspring.profiles.active=test Edit: To add this to tomcat in eclipse, select Run -> Run Configurations and choose your Tomcat run configuration. Click the Arguments tab

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

依然范特西╮ 提交于 2019-11-27 20:31:34
问题 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 instance) to choose from but with different profiles... Say for instance I have two PropertySourcesPlaceholderConfigurer beans configured with "default" and "dev" values a environment profiles. If I use the following profile activation: -Dspring.profiles

How to set spring active profiles with maven profiles

断了今生、忘了曾经 提交于 2019-11-27 07:11:10
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 can reference them in bean signature ( @profile ). but i am not sure how to do it. for example: consider the following maven setup <profiles> <profile> <id>profile1</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> </properties> </profile> <profile> <id>profile2</id> <properties> </properties> </profile> <profile>

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

对着背影说爱祢 提交于 2019-11-27 06:34:57
I need to code different logic based on different current Environment profile. How can you get the current active and default profiles from Spring? aweigold You can autowire the Environment @Autowired Environment env; Environment offers: String[] getActiveProfiles() , String[] getDefaultProfiles() , and boolean acceptsProfiles(String... profiles) Extending User1648825's nice simple answer (I can't comment and my edit was rejected): @Value("${spring.profiles.active}") private String activeProfile; This may throw an IllegalArgumentException if no profiles are set (I get a null value). This may

How to set spring active profiles with maven profiles

狂风中的少年 提交于 2019-11-26 17:36:03
问题 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 can reference them in bean signature ( @profile ). but i am not sure how to do it. for example: consider the following maven setup <profiles> <profile> <id>profile1</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties>

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

让人想犯罪 __ 提交于 2019-11-26 12:38:22
问题 I need to code different logic based on different current Environment profile. How can you get the current active and default profiles from Spring? 回答1: You can autowire the Environment @Autowired Environment env; Environment offers: String[] getActiveProfiles(), String[] getDefaultProfiles(), and boolean acceptsProfiles(String... profiles) 回答2: Extending User1648825's nice simple answer (I can't comment and my edit was rejected): @Value("${spring.profiles.active}") private String