简体   繁体   English

spring profile / servlet上下文根

[英]spring profile / servlet context root

I would like to set the spring profile based on the servlet context root, in servlet 2.5 environment 我想在servlet 2.5环境中基于servlet上下文根设置spring配置文件

I tried with ApplicationContextInitializer, but was not able figure out how to access the context root from it 我尝试了ApplicationContextInitializer,但无法弄清楚如何从中访问上下文根

Is this possible, either with ApplicationContextInitializer or another method? 这可能是ApplicationContextInitializer或其他方法吗?

Try to use ConfigurableWebApplicationContext as it follows 尝试使用ConfigurableWebApplicationContext ,如下所示

public class RuntimeEnvironmentInitializer implements ApplicationContextInitializer<ConfigurableWebApplicationContext> {

private ConfigurableWebApplicationContext configurableApplicationContext;

@Override
    public void initialize(ConfigurableWebApplicationContext arg0) {
        this.configurableApplicationContext = arg0;
        String valueString = arg0.getServletContext().getInitParameter("InitParam");
        configurableApplicationContext.getEnvironment().setActiveProfiles("prod");
    }
}

Not sure if this works but have a try. 不确定这是否有效,但试一试。

Also check the API for that class, have a getServletConfig and getServletContext so you will be able to take some information for it, use ServletContext object if you need it. 还要检查该类的API ,拥有一个getServletConfig和getServletContext,这样您就可以获取一些信息,如果需要,可以使用ServletContext对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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