CloudStackContextLoaderListener

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.spring.module.web; import java.io.IOException; import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent; import org.apache.cloudstack.spring.module.factory.CloudStackSpringContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.ContextLoaderListener; public class CloudStackContextLoaderListener extends ContextLoaderListener { public static final String WEB_PARENT_MODULE = "parentModule";
public static final String WEB_PARENT_MODULE_DEFAULT = "web"; private static final Logger log = LoggerFactory.getLogger(CloudStackContextLoaderListener.class); CloudStackSpringContext cloudStackContext;
String configuredParentName; @Override
protected ApplicationContext loadParentContext(ServletContext servletContext) {
return cloudStackContext.getApplicationContextForWeb(configuredParentName);
} @Override //上下文初始化,通过servlet内容事件
public void contextInitialized(ServletContextEvent event) {
try {
cloudStackContext = new CloudStackSpringContext();
event.getServletContext().setAttribute(CloudStackSpringContext.CLOUDSTACK_CONTEXT_SERVLET_KEY, cloudStackContext);
} catch (IOException e) {
log.error("Failed to start CloudStack", e);
throw new RuntimeException("Failed to initialize CloudStack Spring modules", e);
} configuredParentName = event.getServletContext().getInitParameter(WEB_PARENT_MODULE);
if ( configuredParentName == null ) {
configuredParentName = WEB_PARENT_MODULE_DEFAULT;
} super.contextInitialized(event);
} @Override
protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) {
super.customizeContext(servletContext, applicationContext); String[] newLocations = cloudStackContext.getConfigLocationsForWeb(configuredParentName,
applicationContext.getConfigLocations());

     //设置应用到新的位置
applicationContext.setConfigLocations(newLocations);
} }

CloudStack采用spring加载bean(cloud-framework-spring-module模块)的更多相关文章

  1. spring加载bean流程解析

    spring作为目前我们开发的基础框架,每天的开发工作基本和他形影不离,作为管理bean的最经典.优秀的框架,它的复杂程度往往令人望而却步.不过作为朝夕相处的框架,我们必须得明白一个问题就是sprin ...

  2. Dubbo实践(六)Spring加载Bean流程

    根据上一小节对于spring扩展schema的介绍,大概可以猜到dubbo中相关的内容是如何实现的. 再来回顾Dubbo实践(一)中定义的dubbo-provider.xml: <?xml ve ...

  3. spring加载Bean的解析过程(二)

    1.例如: BeanFactory bf = new XmlBeanFactory(new ClassPathResource("spring.xml")); User user ...

  4. spring加载bean实例化顺序

    问题来源: 有一个bean为 A,一个bean为B.想要A在容器实例化的时候的一个属性name赋值为B的一个方法funB的返回值. 如果只是在A里单纯的写着: private B b;private ...

  5. spring 加载bean过程源码简易解剖(转载)

    这一篇主要是讲用载入bean的过程.其实就是IOC.低调 低调.. 我把重要的都挑出来了.一步步往下看就明白spring载入bean.xml里面bean的原理 . 感觉像候杰的 MFC深入浅出,哈哈. ...

  6. Spring加载applicationContext.xml实现spring容器管理的几种方式

    package com.etc.test; import org.junit.Test; import org.springframework.beans.factory.BeanFactory; i ...

  7. spring加载bean报错:expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

    看具体报错日志: 警告: Unable to proxy interface-implementing method [public final void cn.wlf.selection.proto ...

  8. Spring加载applicationContext.xml实现spring容器管理的单例模式

    package com.etc.pojo; import org.springframework.context.ApplicationContext; import org.springframew ...

  9. Spring多种加载Bean方式简析

    1 定义bean的方式 常见的定义Bean的方式有: 通过xml的方式,例如: <bean id="dictionaryRelMap" class="java.ut ...

随机推荐

  1. Velocity+Java较全教程

    一.安装myEclipse 二.安装velocity的eclipse插件: http://www.oschina.net/p/veloeclipse(介绍) 方法1(现在基本上非常慢)http://p ...

  2. bjfu1287字符串输出的大水题

    不多说 /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> # ...

  3. selenium python (十三)对于分页的处理

    #!/usr/bin/python# -*- coding: utf-8 -*-__author__ = 'zuoanvip' #对于web上分页的功能,一般做如下操作:    #获取总页数    # ...

  4. Java之--Java语言基础组成(关键字、标识符、注释、常量和变量、运算符)

    Java语言基础组成-关键字.标识符.注释.常量和变量.运算符 Java语言由8个模块构成,分别为:1.关键字:2.标识符(包名.类名.接口名.常量名.变量名等):3.注释:4.常量和变量:5.运算符 ...

  5. erase() 返回的是删除此元素之后的下一个元素的迭代器 .xml

    pre{ line-height:1; color:#f0caa6; background-color:#2d161d; font-size:16px;}.sysFunc{color:#e54ae9; ...

  6. 【LeetCode】139 - Word Break

    Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...

  7. 刚刚大学毕业,自己搭网站遇到的问题 一:tomcat中同时部署两个项目的问题

    最近直接把两个项目打成war包在tomcat下发布,出现了很多莫名奇妙的问题,就是不能发布成功,只能有一个项目能成功,在网上查了很多方法,以为是两个项目中jar包出现冲突,也按照网上的方法把两个项目中 ...

  8. 看过的bootstrap书籍(附下载地址)

    http://yun.baidu.com/share/link?shareid=3820784617&uk=1008683945 以下书籍下载地址. <BootStrap入门教程> ...

  9. MATLAB将矩阵使用.txt文件格式保存

    具体的命令是:用save *.txt -ascii x x为变量 *.txt为文件名,该文件存储于当前工作目录下,再打开就可以 打开后,数据有可能是以指数形式保存的.   看下面这个例子: a =[1 ...

  10. Hadoop概述

    本章内容 什么是Hadoop Hadoop项目及其结构 Hadoop的体系结构 Hadoop与分布式开发 Hadoop计算模型—MapReduce Hadoop的数据管理 小结 1.1 什么是Hado ...