简体   繁体   中英

How to set active Spring profile with web parameter

I'm working on a legacy Servlet app, where I'm taking Spring to help (not Spring MVC). The Spring configuration is working fine at the moment and I can set the active profile either by command line or programmatically. This blog post states that the active Spring profile can be set as a web parameter also. However, I'm unable to make this option work.

I've simply tried to make a request to the servlet as localhost://foo?spring.profiles.active=foo , but this does not work as expected.

What is the correct way of passing the web parameter for the active Spring profile? Is this something Spring MVC specific?

Spring needs to know the profile when the application context is being constructed - ie during web application startup. The Web parameter method refers to context parameter set via web.xml :

<context-param>
    <param-name>spring.profiles.active</param-name>
    <param-value>development</param-value>
</context-param>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM