Skip to Content
0
Former Member
Oct 11, 2016 at 04:37 PM

Spring active profile ambiguity

259 Views

Hi,

I'm having trouble with setting some bean to be active only when spring profile is set to production.

Basically, what happens is that when I run my integration tests,it looks like my production profile is also active, and it shouldn't be.

Relevant part of local_tenant_junit.properties:

 spring.profiles.active=myextension_test

myextension's relevant part of project.properties:

 spring.profiles.active=myextension_prod


Now the things get interesting. Here is the part of my test class:

 @Resource
 private Environment environment;
 
 @Resource
 private ConfigurationService configurationService;
 
 @Test
 public void dummyTest() {
   String first = (String ) configurationService.getConfiguration().getProperty("spring.profiles.active");
   String[] second = environment.getActiveProfiles();
   assertTrue(true);
 }
 

When I run this test, variable "first" has value "myextension_test", and variable "second" has value ["myextension_test", "myextension_prod", "tenant_junit"]. How come that these 2 variables differ? I was expecting only myextension_test profiile to be active. OK, I understand tenant_junit also, but why did Hybris also activated myextension_prod profile ? Looks like local_tenant_junit.properties merged with project.properties, instead of overriding it.

I ran my tests with "ant integrationtests" command.

Did anybody have similar problems?

Thanks in advance, Antun