spring-profiles

Yml config files “Inheritance” with Spring boot

无人久伴 提交于 2019-12-03 11:59:47
I couldn't find a straight answer online. Do Spring Boot's yml files "inherit" from each other? I mean if I have: application.yml which has server: port: 80 host: foo and application-profile1.yml which has only server: port: 90 So if I start my Spring Boot with profile1 as active profile, will I also have server.host property set to foo ? Yes, application.yml file has higher precedence over any application-{profile}.yml file. Properties from profile specific yml file will override values from the default application.yml file and properties that do not exist in profile specific yml file will be

Spring Profiles on method level?

血红的双手。 提交于 2019-12-02 22:27:53
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 configured in properties? spring.profiles.active=dev Take the following as pseudocode. How can this be done? class MyService { void run() { log(); } @Profile("dev") void log() { //only during dev } } Andres AS you can read on http://docs.spring.io/spring/docs/3.1.x/javadoc-api/org/springframework/context/annotation/Profile.html The @Profile

Use @Profile to decide to execute test class

狂风中的少年 提交于 2019-12-02 17:11:10
问题 According to https://stackoverflow.com/a/33042872/4106030 we should not use @Profile to let a spring profile decide whether all tests in a test class shall be executed or ignored. There is stated: @Profile is used to selectively enable a component (e.g., @Service , etc.), @Configuration class, or @Bean method if one of the named bean definition profiles is active in the Spring Environment for the ApplicationContext. This annotation is not directly related to testing: @Profile should not be

Use @Profile to decide to execute test class

杀马特。学长 韩版系。学妹 提交于 2019-12-02 07:49:12
According to https://stackoverflow.com/a/33042872/4106030 we should not use @Profile to let a spring profile decide whether all tests in a test class shall be executed or ignored. There is stated: @Profile is used to selectively enable a component (e.g., @Service , etc.), @Configuration class, or @Bean method if one of the named bean definition profiles is active in the Spring Environment for the ApplicationContext. This annotation is not directly related to testing: @Profile should not be used on a test class . Is this true? If yes then why? It's true because @Profile effects Spring

Gradle build spring boot app as war with active profile

拜拜、爱过 提交于 2019-12-01 18:25:11
I would like to package my spring boot application as war for a specific profile. That can be done with setting spring.profiles.active= profile name in application.properties file. Is it possible to set it as a parameter when building war eg. gradle build --spring.profiles.active= profile name ? It sounds like you want to bake the value of spring.profiles.active into the war when it's built. You can do so using Gradle's support for resource filtering. Configure your application.properties like this: spring.profiles.active=@activeProfiles@ And then apply filtering in your build.gradle to

Spring: How to do AND in Profiles?

五迷三道 提交于 2019-11-30 12:29:17
问题 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 profile B is active. Our use case is different we want to support TEST and PROD versions of multiple configurations. Therefore sometimes we want to autowire the bean only if both profiles TEST and CONFIG1 are active. Is there any way to do it with

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

天涯浪子 提交于 2019-11-30 08:46:38
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, e.g.: spring.application.name=app-name spring.cloud.config.uri=http://default-config-server.com --- spring.profiles=dev spring.cloud.config.uri=http://dev-config-server.com --- spring.profiles=stage spring.cloud.config.uri=http://stage-config-server.com --- spring.profiles=prod spring.cloud.config.uri=http://prod-config-server.com And then I set the cla -Dspring.profiles.active=dev but

Spring Boot Programmatically setting profiles

﹥>﹥吖頭↗ 提交于 2019-11-30 06:47:05
问题 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

Spring: How to do AND in Profiles?

梦想与她 提交于 2019-11-30 02:46:55
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 profile B is active. Our use case is different we want to support TEST and PROD versions of multiple configurations. Therefore sometimes we want to autowire the bean only if both profiles TEST and CONFIG1 are active. Is there any way to do it with Spring? What would be the simplest way? Since Spring does not provide the AND feature out of the box. I

Setting Spring Profile variable

霸气de小男生 提交于 2019-11-29 20:23:37
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? 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 and add -Dspring.profiles.active=test at the end of VM arguments . Another way would be to add the property