spring-profiles

Change a file that is same in all profiles?

情到浓时终转凉″ 提交于 2019-12-13 02:55:50
问题 I have four profiles which differ in static files. Should I have four different resources to switch between them? Then What if we want to change one of the files that is same in all resorces? Should we change all four resources files? If I want to explain more, consider you want to change index.html file for all profiles but have different login.html file for each profile. Now I have four static profiles like dev-static, prod-static and ... . Is there any way I don't change all four index

What happens in Spring if I use the @ActiveProfiles annotation on a configuration class instead use it on the class that defines my beans?

妖精的绣舞 提交于 2019-12-12 08:34:05
问题 I am studying for the Spring Core certification and I have some doubts related to the use of profiles into JUnit tests . So I know that if I annote a class in the following way: @Profile("stub") @Repository public class StubAccountRepository implements AccountRepository { private Logger logger = Logger.getLogger(StubAccountRepository.class); private Map<String, Account> accountsByCreditCard = new HashMap<String, Account>(); /** * Creates a single test account with two beneficiaries. Also logs

Spring Boot: Profiles ignored in PropertySourcesPlaceholderConfigurer loaded file

泪湿孤枕 提交于 2019-12-11 03:52:15
问题 I have a library that is a Spring Boot project. The library has a library.yml file that contains dev and prod props for its configuration: library.yml --- spring: profiles: active: dev --- spring: profiles: dev env: dev --- spring: profiles: prod env: prod Another application uses this library and loads the props using: @Bean public static PropertySourcesPlaceholderConfigurer dataProperties() { PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new

Is Spring's @Profile on methods a good practice

时光毁灭记忆、已成空白 提交于 2019-12-10 19:00:28
问题 I have a Spring Boot Web application exposing rest services. I'm asking myself how to correctly manage profiles on Filters. Actually, my app has 2 profiles: dev and prod (you guess what it stands for...) In prod mode, i have more filters to activate than in dev mode. My Filters configuration class is the following: @Configuration public class FiltersConfig { @Bean public FilterRegistrationBean filterRegistrationBean(CompositeFilter compositeFilter){ FilterRegistrationBean

Yml config files “Inheritance” with Spring boot

為{幸葍}努か 提交于 2019-12-09 09:25:30
问题 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 ? 回答1: Yes, application.yml file has higher precedence over any application-{profile}.yml file. Properties from profile specific yml file will override values

Not loading a Spring bean when a certain profile is set

空扰寡人 提交于 2019-12-06 20:13:04
问题 Background: So, I've got several beans that interface external systems. For development, it's convenient to mock the external systems and replace the interfacing beans with some implementations that produce more or less static responses. So what I've been doing is to create an interface, the real implementation and a stub implementation like this: public interface ExternalService { // ... } @Service public class ExternalServiceImpl implements ExternalService { // ... } @Service @Primary

Including bean definition when a profile is NOT active

喜你入骨 提交于 2019-12-04 23:37:06
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 is like this: Let's suppose we have a list of all possible profiles, e.g. {A, B, C, D}. Profiles active for particular execution are {A, C}. What I do is I create artificial profiles for all possible profiles which are not active. In the example case I would create {not_B, not_D} profiles. The beans I want to be active based on not active profile X I

Spring Profiles on method level?

六月ゝ 毕业季﹏ 提交于 2019-12-04 08:19:14
问题 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 } } 回答1: AS you can read on http://docs.spring.io

Gradle build spring boot app as war with active profile

为君一笑 提交于 2019-12-04 03:41:53
问题 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 ? 回答1: 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

What happens in Spring if I use the @ActiveProfiles annotation on a configuration class instead use it on the class that defines my beans?

做~自己de王妃 提交于 2019-12-04 03:35:51
I am studying for the Spring Core certification and I have some doubts related to the use of profiles into JUnit tests . So I know that if I annote a class in the following way: @Profile("stub") @Repository public class StubAccountRepository implements AccountRepository { private Logger logger = Logger.getLogger(StubAccountRepository.class); private Map<String, Account> accountsByCreditCard = new HashMap<String, Account>(); /** * Creates a single test account with two beneficiaries. Also logs creation * so we know which repository we are using. */ public StubAccountRepository() { logger.info(