2015-02-12 52 views
0

我想2.5環境春天資料/ servlet上下文根

我試圖與ApplicationContextInitializer,但無法弄清楚如何從訪問上下文根設置基於servlet上下文根彈簧輪廓,在servlet的它

這是可能的,無論是與ApplicationContextInitializer或其他方法?

回答

0

嘗試使用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"); 
    } 
} 

不知道這工作,但有一個嘗試。

還請檢查該類的API,有一個getServletConfig和getServletContext,以便您可以獲取一些信息,如果需要它可以使用ServletContext對象。

+0

謝謝@Koitoer,那正是我所需要的,我正在尋找一種方法來調用getServletContext – indybee 2015-02-12 01:19:18