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 ...
随机推荐
- UITabbar item 设置笔记
很长一段时间都是用代码来写UITabbarController,试着用xib来写一次,但是遇到tabbar item的图标自定义的时候不知道从何入手,比如定义选定前和选定后的icon图片,这地方还是不 ...
- Android下EditText的hint的一种显示效果------FloatLabelLayout
效果: 此为EditText的一种细节,平时可能用的不多,但是用户体验蛮好的,特别是当注册页面的项目很多的时候,加上这种效果,体验更好 仅以此记录,仅供学习参考. 参考地址:https://gist. ...
- RAC实例 表空间 维护
先配置一下监听,这样我们就可以从客户端进行连接了. 我这里写了三种连接. 第一种是正常方式,一般都采用这种方式,后面的rac1和rac2 是方便测试.因为如果用第一种方式的话,客户端连哪个实例是随机的 ...
- Creole
Home Bisher besucht: AnzeigenAnhängeInfo The Creole 1.0 project has been succ ...
- 最全的PHP开发Android应用程序
第一部分是指在Android系统的手机上直接写PHP脚本代码并立即运行: 第二部分则继续讲解如何把写好的PHP脚本代码打包成akp安装文件. 首先,在手机上安装两个apk包. 一个是SL4A(Scri ...
- mybatis注解详解
首 先当然得下载mybatis-3.0.5.jar和mybatis-spring-1.0.1.jar两个JAR包,并放在WEB-INF的lib目录下 (如果你使用maven,则jar会根据你的pom配 ...
- CDB和PDB基本管理
CDB和PDB基本管理 这篇文章主要介绍CDB和PDB的基本管理,资料来源oracle官方. 基本概念: Multitenant Environment:多租户环境 CDB(Container Dat ...
- android 性能优化大纲
性能优化系列 分为三个部分:视图篇 逻辑篇 和代码规范篇 . ------2016/9/6 视图篇 主要涵盖视图树层级优化.自定义视图.图片优化,常用布局性能缺陷等多个方面 .把平常经常 ...
- 数往知来 ASP.NET 模拟服务器:服务端_静态页面_动态页面的响应<十七>
一.客户端是怎么看到我们的网页的呢/ 在浏览器端,如果用汉语请求的是一普通的HTML网页,呢么我们的IIS服务器, 接收到请求以后,那么从IIS服务器所在的电脑区查找该HTML网页, 找到以后将该 ...
- Java Core 学习笔记——3.char/Unicode/代码点/代码单元
通用字符集(UCS) UCS是由ISO制定的ISO 10646(或称ISO/IEC 10646)标准所制定的标准字符集. UCS包括了其他所有的字符集(包含了已知语言的所以字符). ISO/IEC 1 ...