CloudStack采用spring加载bean(cloud-framework-spring-module模块)
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模块)的更多相关文章
- spring加载bean流程解析
spring作为目前我们开发的基础框架,每天的开发工作基本和他形影不离,作为管理bean的最经典.优秀的框架,它的复杂程度往往令人望而却步.不过作为朝夕相处的框架,我们必须得明白一个问题就是sprin ...
- Dubbo实践(六)Spring加载Bean流程
根据上一小节对于spring扩展schema的介绍,大概可以猜到dubbo中相关的内容是如何实现的. 再来回顾Dubbo实践(一)中定义的dubbo-provider.xml: <?xml ve ...
- spring加载Bean的解析过程(二)
1.例如: BeanFactory bf = new XmlBeanFactory(new ClassPathResource("spring.xml")); User user ...
- spring加载bean实例化顺序
问题来源: 有一个bean为 A,一个bean为B.想要A在容器实例化的时候的一个属性name赋值为B的一个方法funB的返回值. 如果只是在A里单纯的写着: private B b;private ...
- spring 加载bean过程源码简易解剖(转载)
这一篇主要是讲用载入bean的过程.其实就是IOC.低调 低调.. 我把重要的都挑出来了.一步步往下看就明白spring载入bean.xml里面bean的原理 . 感觉像候杰的 MFC深入浅出,哈哈. ...
- Spring加载applicationContext.xml实现spring容器管理的几种方式
package com.etc.test; import org.junit.Test; import org.springframework.beans.factory.BeanFactory; i ...
- 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 ...
- Spring加载applicationContext.xml实现spring容器管理的单例模式
package com.etc.pojo; import org.springframework.context.ApplicationContext; import org.springframew ...
- Spring多种加载Bean方式简析
1 定义bean的方式 常见的定义Bean的方式有: 通过xml的方式,例如: <bean id="dictionaryRelMap" class="java.ut ...
随机推荐
- Android SurfaceView使用详解
1. SurfaceView的定义前面已经介绍过View了,下面来简单介绍一下SurfaceView,参考SDK文档和网络资料:SurfaceView是View的子类,它内嵌了一个专门用于绘制的Sur ...
- Python学习2-列表和元组
Python学习2-列表和元组 标签(空格分隔): 列表 元组 在Python中,最基本的数据结构是序列(sequence).序列中的每个元素被分配一个序号--即元素的位置,也称为索引.索引从0开始. ...
- vhosts.conf
<VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/opt/lampp/ ...
- Math.random();函数 随机数
random函数参数 无参数 random函数返回值 返回0和1之间的伪随机数,可能为0,但总是小于1,[0,1) random函数示例 document.write(Math.random()); ...
- 常见排序算法基于JS的实现
一:冒泡排序 1. 原理 a. 从头开始比较相邻的两个待排序元素,如果前面元素大于后面元素,就将二个元素位置互换 b. 这样对序列的第0个元素到n-1个元素进行一次遍历后,最大的一个元素就“沉”到序列 ...
- nginx上传目录配置,禁止执行权限
我们经常会把网站的图片文件上传目录设置为只可上传文件但不能执行文件,就是要禁止执行权限,小编来给大家举一个上传目录配置,禁止执行权限方法,各位可参考. 如果不让有执行权限最简单的办法 代码如下 复制 ...
- Delphi Val函数
在这里Val和iif都是你所用的数据库中的函数在delphi中Val是一个将字符串转换为数字的函数,Val(S; var V; var Code: Integer)第一个参数是要转换的字符串,第二个参 ...
- HTTP协议学习笔记-1
基本概念 首先需要了解几个概念: WEB客户端和服务器: WEB客户端当然就是指我们用使用的某个网站 服务器就是WEB资源源头,我们从服务器去请求数据,服务器把请求的数据发给WEB客户端 媒体类型: ...
- [转]Linux之type命令
转自:http://codingstandards.iteye.com/blog/831504 用途说明 type命令用来显示指定命令的类型.一个命令的类型可以是如下之一 alias 别名 keywo ...
- 关于Cygwin的x-Server的自动运行以及相关脚本修改
常常需要用到远端服务器的图形工具,如果在windows端没用xserver的话,很多程序无法运行.一个特殊的例子,emacs在没用xserver的时候,是直接在终端中打开的,如果不修改cygwin.b ...