Change Active Spring Profiles at run time

2

I usually use this code snippet to set the profile of the application

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
    <param-name>spring.profiles.active</param-name>
    <param-value>production</param-value>
</init-param>
</servlet>

Is there any way to do this at run time through a controller ?

    
asked by anonymous 25.03.2014 / 18:12

1 answer

1

Yes, it is possible to do it programatically via java. Use as follows:

ctx.getEnvironment().setActiveProfiles("container");

Where ctx is your spring context.
Source: link

I hope I have helped.

    
26.03.2014 / 15:31