cancel
Showing results for 
Search instead for 
Did you mean: 

Spring active profile ambiguity

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

I managed to make a workaround by using @Conditional annotation, in case anyone is interested.

Former Member
0 Kudos

How did you implement?