1

I want to create 2 spring profiles , one runs in test and others in other environments. Depending on a profile that is inactive , i need to define some beans. So essentially want to do below

e.g.

<beans profile="test">
<bean id="testconstructorBean" 
....
</beans>
<!- is test is not available-->
<beans profile="!test">
<bean id="constructorBean"
...
</beans>

I have seen on reference spring profles group, which can also work. But what i want is to have 2 alternative configurations which cannot coexists.

Regards N

alexbt
  • 16,415
  • 6
  • 78
  • 87
nissshh
  • 13
  • 5
  • Not sure if I totally understand, you can use `profile="!test"` right, that is a valid construct, are you having issues in using this construct? – Biju Kunjummen Oct 29 '13 at 19:23

1 Answers1

1

You could implement a WebApplicationInitializer and set the spring.profiles.active programmatically based on your conditions.

This article discusses ways to set profiles based on environments, which sounds like what you are looking for.

Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
  • But the declaration only defines active profiles and does not activates any grouping/disabled profiles. – nissshh Oct 29 '13 at 19:18
  • I don't really understand your comment. But with the way I suggested, you should be able to active either profile (or both if you wanted to, but it doesn't sound like you). If you only active one, the other will be disabled. Is that what you want? – Jeff Storey Oct 29 '13 at 19:34
  • I want to handle cases where we have profiles like DEV/SIT/UAT/PROD and another as TEST. I want some beans to be only active if TEST profile is provided, regardless if other profiles are active or not. Hope this helps. – nissshh Nov 07 '13 at 20:27
  • But in that case i have to make sure that I activate those profiles. `code` <!- is test is not available--> `code` , but my actual intent if to create a bean with different configuration for TEST and NONTEST environment. – nissshh Nov 07 '13 at 20:31
  • Correct, you need different active profiles for each one. You can put the beans in different files, and then each profile will load one of those bean files. – Jeff Storey Nov 07 '13 at 20:35