本文整理匯總了Java中org.springframework.web.context.ConfigurableWebApplicationContext.setServletContext方法的典型用法代碼示例。如果您正苦於以下問題:Java ConfigurableWebApplicationContext.setServletContext方法的具體用法?Java ConfigurableWebApplicationContext.setServletContext怎麽用?Java ConfigurableWebApplicationContext.setServletContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.context.ConfigurableWebApplicationContext
的用法示例。
在下文中一共展示了ConfigurableWebApplicationContext.setServletContext方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: configureAndRefreshWebApplicationContext
import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) {
if (ObjectUtils.identityToString(wac).equals(wac.getId())) {
// The application context id is still set to its original default value
// -> assign a more useful id based on available information
if (this.contextId != null) {
wac.setId(this.contextId);
}
else {
// Generate default id...
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
ObjectUtils.getDisplayString(getServletContext().getContextPath()) + "/" + getServletName());
}
}
wac.setServletContext(getServletContext());
wac.setServletConfig(getServletConfig());
wac.setNamespace(getNamespace());
wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener()));
// The wac environment's #initPropertySources will be called in any case when the context
// is refreshed; do it eagerly here to ensure servlet property sources are in place for
// use in any post-processing or initialization that occurs below prior to #refresh
ConfigurableEnvironment env = wac.getEnvironment();
if (env instanceof ConfigurableWebEnvironment) {
((ConfigurableWebEnvironment) env).initPropertySources(getServletContext(), getServletConfig());
}
postProcessWebApplicationContext(wac);
applyInitializers(wac);
wac.refresh();
}
示例2: initialize
import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
@Override
public void initialize(ConfigurableWebApplicationContext applicationContext) {
applicationContext.setServletContext(this.servletContext);
if (this.addApplicationContextAttribute) {
this.servletContext.setAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
applicationContext);
}
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:11,代碼來源:ServletContextApplicationContextInitializer.java
示例3: createWebApplicationContext
import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
/**
* Instantiate the WebApplicationContext for the ActionServlet, either a default
* XmlWebApplicationContext or a custom context class if set.
* <p>This implementation expects custom contexts to implement ConfigurableWebApplicationContext.
* Can be overridden in subclasses.
* @throws org.springframework.beans.BeansException if the context couldn't be initialized
* @see #setContextClass
* @see org.springframework.web.context.support.XmlWebApplicationContext
*/
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
throws BeansException {
if (logger.isDebugEnabled()) {
logger.debug("ContextLoaderPlugIn for Struts ActionServlet '" + getServletName() +
"', module '" + getModulePrefix() + "' will try to create custom WebApplicationContext " +
"context of class '" + getContextClass().getName() + "', using parent context [" + parent + "]");
}
if (!ConfigurableWebApplicationContext.class.isAssignableFrom(getContextClass())) {
throw new ApplicationContextException(
"Fatal initialization error in ContextLoaderPlugIn for Struts ActionServlet '" + getServletName() +
"', module '" + getModulePrefix() + "': custom WebApplicationContext class [" +
getContextClass().getName() + "] is not of type ConfigurableWebApplicationContext");
}
ConfigurableWebApplicationContext wac =
(ConfigurableWebApplicationContext) BeanUtils.instantiateClass(getContextClass());
wac.setParent(parent);
wac.setServletContext(getServletContext());
wac.setNamespace(getNamespace());
if (getContextConfigLocation() != null) {
wac.setConfigLocations(
StringUtils.tokenizeToStringArray(
getContextConfigLocation(), ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));
}
wac.addBeanFactoryPostProcessor(
new BeanFactoryPostProcessor() {
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
beanFactory.addBeanPostProcessor(new ActionServletAwareProcessor(getActionServlet()));
beanFactory.ignoreDependencyType(ActionServlet.class);
}
}
);
wac.refresh();
return wac;
}
示例4: init
import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
public void init() {
logger.info(I18n.getLocaleMessage("ext.began.pring.containers.initialization"));
if (factory == null){
if(this.configLocation!=null&&!"".equals(this.configLocation)){
this.factory= new ClassPathXmlApplicationContext(this.configLocation.split(";"));
}else{
this.factory=new ClassPathXmlApplicationContext("classpath: applicationContext.xml");
}
}
if (factory instanceof AbstractApplicationContext) {
AbstractApplicationContext context = (AbstractApplicationContext) factory;
if (factory instanceof ConfigurableWebApplicationContext) {
// 這裏的代碼不直觀
ConfigurableWebApplicationContext webContext = (ConfigurableWebApplicationContext) factory;
if (parent != null && parent instanceof WebContextContainer) {
webContext.setServletContext(((WebContextContainer) parent)
.getServletContext());
}
if (!haveStart) {
context.refresh();
haveStart = true;
}
}
if(parent!=null && parent instanceof WebContextContainer)
{
this.registerWebContext(((WebContextContainer) parent).getServletContext());
}
}
logger.info(I18n.getLocaleMessage("ext.Spring.container.initialized"));
}
示例5: createWebApplicationContext
import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
protected WebApplicationContext createWebApplicationContext(ServletContext servletContext, ApplicationContext parent)
throws BeansException {
ConfigurableWebApplicationContext wac = new TavernXmlWebApplicationContext(pluginContext);
try {
wac.setServletContext(servletContext);
wac.setConfigLocation(application.getConfig().getContextPath() == null ? servletContext
.getInitParameter(CONFIG_LOCATION_PARAM) : application.getConfig().getContextPath());
customizeContext(servletContext, wac);
} catch (Exception e){
logger.error("init fail "+application,e);
}
return wac;
}
示例6: initialize
import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
@Override
public void initialize(ConfigurableWebApplicationContext applicationContext) {
applicationContext.setServletContext(this.servletContext);
}
示例7: configureAndRefreshWebApplicationContext
import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) {
if (ObjectUtils.identityToString(wac).equals(wac.getId())) {
// The application context id is still set to its original default value
// -> assign a more useful id based on available information
if (this.contextId != null) {
wac.setId(this.contextId);
}
else {
// Generate default id...
ServletContext sc = getServletContext();
if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
// Servlet <= 2.4: resort to name specified in web.xml, if any.
String servletContextName = sc.getServletContextName();
if (servletContextName != null) {
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + servletContextName +
"." + getServletName());
}
else {
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + getServletName());
}
}
else {
// Servlet 2.5's getContextPath available!
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
ObjectUtils.getDisplayString(sc.getContextPath()) + "/" + getServletName());
}
}
}
wac.setServletContext(getServletContext());
wac.setServletConfig(getServletConfig());
wac.setNamespace(getNamespace());
wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener()));
// The wac environment's #initPropertySources will be called in any case when the context
// is refreshed; do it eagerly here to ensure servlet property sources are in place for
// use in any post-processing or initialization that occurs below prior to #refresh
ConfigurableEnvironment env = wac.getEnvironment();
if (env instanceof ConfigurableWebEnvironment) {
((ConfigurableWebEnvironment) env).initPropertySources(getServletContext(), getServletConfig());
}
postProcessWebApplicationContext(wac);
applyInitializers(wac);
wac.refresh();
}
示例8: contextInitialized
import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "REC_CATCH_EXCEPTION")
public void contextInitialized(ServletContextEvent servletContextEvent) {
ServletContext servletContext = servletContextEvent.getServletContext();
StringBuilder configLocation = new StringBuilder();
configLocation.append("classpath:org/geomajas/spring/geomajasContext.xml");
String additionalLocations = servletContext.getInitParameter(CONFIG_LOCATION_PARAMETER);
if (null != additionalLocations) {
for (String onePart : additionalLocations.split("\\s")) {
String part = onePart.trim();
if (part.length() > 0) {
configLocation.append(',');
int pos = part.indexOf(':');
if (pos < 0) {
// no protocol specified, use classpath.
configLocation.append(GeomajasConstant.CLASSPATH_URL_PREFIX);
} else if (0 == pos) {
// location starts with colon, use default application context
part = part.substring(1);
}
configLocation.append(part);
}
}
}
ConfigurableWebApplicationContext applicationContext = new XmlWebApplicationContext();
// Assign the best possible id value.
String id;
try {
String contextPath = (String) ServletContext.class.getMethod("getContextPath").invoke(servletContext);
id = ObjectUtils.getDisplayString(contextPath);
} catch (Exception ex) {
// Servlet <= 2.4: resort to name specified in web.xml, if any.
String servletContextName = servletContext.getServletContextName();
id = ObjectUtils.getDisplayString(servletContextName);
}
applicationContext.setId("Geomajas:" + id);
applicationContext.setServletContext(servletContext);
applicationContext.setConfigLocation(configLocation.toString());
applicationContext.refresh();
ApplicationContextUtil.setApplicationContext(servletContext, applicationContext);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
}