SpringUtil
/** SpringUtil.java
{{IS_NOTE
Purpose:
Description:
History:
Thu Jun 1 13:53:53 2006, Created by henrichen
}}IS_NOTE
Copyright (C) 2006 Potix Corporation. All Rights Reserved.
{{IS_RIGHT
}}IS_RIGHT
*/
package org.zkoss.zkplus.spring;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.BeanNotOfRequiredTypeException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.UiException;
/***
* SpringUtil, a Spring utility.
* <p>Applicable to Spring Framework version 2.x or later</p>
* @author henrichen
*/
public class SpringUtil {
/***
* Get the spring application context.
*/
public static ApplicationContext getApplicationContext() {
Execution exec = Executions.getCurrent();
if (exec == null) {
throw new UiException("SpringUtil can be called only under ZK environment!");
}
return WebApplicationContextUtils.getRequiredWebApplicationContext(
(ServletContext)exec.getDesktop().getWebApp().getNativeContext());
}
/***
* Get the spring bean by the specified name.
*/
public static Object getBean(String name) {
Object o = null;
try {
if(getApplicationContext().containsBean(name)) {
o = getApplicationContext().getBean(name);
}
} catch (NoSuchBeanDefinitionException ex) {
// ignore
}
return o;
}
/***
* Get the spring bean by the specified name and class.
*/
public static Object getBean(String name, Class cls) {
Object o = null;
try {
if(getApplicationContext().containsBean(name)) {
o = getApplicationContext().getBean(name, cls);
}
} catch (NoSuchBeanDefinitionException ex) {
// ignore
} catch (BeanNotOfRequiredTypeException e) {
// ignore
}
return o;
}
}
转载:http://www.oschina.net/code/explore/zk-src-5.0.5/zkplus/src/org/zkoss/zkplus/spring/SpringUtil.java
SpringUtil的更多相关文章
- java SpringUtil获取bean
package com.whaty.framework.common.spring; import java.io.PrintStream; import org.springframework.be ...
- Tomcat shutdown执行后无法退出进程问题排查及解决
问题定位及排查 上周无意中调试程序在Linux上ps -ef|grep tomcat发现有许多tomcat的进程,当时因为没有影响系统运行就没当回事.而且我内心总觉得这可能是tomcat像nginx一 ...
- shiro权限管理框架与springmvc整合
shiro是apache下的一个项目,和spring security类似,用于用户权限的管理‘ 但从易用性和学习成本上考虑,shiro更具优势,同时shiro支持和很多接口集成 用户及权限管理是众多 ...
- maven-sprigmvc-mybatis配置
pom.xml配置 <?xml version="1.0"?> <project xsi:schemaLocation="http://maven.ap ...
- webService学习之路(二):springMVC集成CXF快速发布webService
继上一篇webService入门之后,http://www.cnblogs.com/xiaochangwei/p/4969448.html ,现在我将我周六在家研究的结果公布出来 本次集成是基于之前已 ...
- shiro在springmvc里面的集成使用【转】
<dependency> <groupId>commons-collections</groupId> <artifactId>commons-coll ...
- 基于Spring+SpringMVC+Mybatis的Web系统搭建
系统搭建的配置大同小异,本文在前人的基础上做了些许的改动,重写数据库,增加依据权限的动态菜单的实现,也增加了后台返回json格式数据的配置,详细参见完整源码. 主要的后端架构:Spring+Sprin ...
- [Java] Spring + SpringMVC + Maven + JUnit 搭建
示例项目下载: https://github.com/yangyxd/SpringDemo 利用前面 SpringMVC 项目的配置方式,完成初步的项目创建.下面只讲一些不同之处. 传送门: [Jav ...
- Spring Data JPA 学习记录1 -- 单向1:N关联的一些问题
开新坑 开新坑了(笑)....公司项目使用的是Spring Data JPA做持久化框架....学习了一段时间以后发现了一点值得注意的小问题.....与大家分享 主要是针对1:N单向关联产生的一系列问 ...
随机推荐
- 源自梦想 自定义ViewGroup的整理_2
Android项目: 1.准备资源图片.图片放到hdip里和mdip里对想过的影响:对于320*480的模拟器,默认去mdip里去找图片资源,拿过来的图片可以直接用,清晰度不变.要是所要找的图片在hd ...
- swift 委托代理传值
委托代理 1.定义个协议 2.声明一个委托代理 3.指定委托代理,调用委托实现的协议方法 4实现LoadingDelegate协议 代码如下: import UIKit //1.定义个协议 proto ...
- Oracle基础 (十三)日期函数
日期函数 SYSDATE --当前系统时间 select sysdate from dual; EXTRACT --获取当前年份 select extract(year from sysdate) f ...
- PHP使用外部命令导出数据库,备份到服务器并下载到本地
<?php // $dumpFileName目录要有可写权限 $DbHost = 'localhost'; $DbUser = 'root'; $DbPwd = '123456'; $DbNam ...
- HDU 4424 Conquer a New Region
http://acm.hdu.edu.cn/showproblem.php?pid=4424 [题目大意] 给你N个点和N-1条边的连通图,也就是说任意两点间的路径是唯一的.每条边有个权值,从一点到另 ...
- Windows 7 无线网络故障
朋友打电话来问为何他的PC不能连接到家里的无线网络,而手机等其他设备都可以?相互交谈之中,我问如下几个问题: 是否可以搜索到其他无线网络? 答:是.(想确实无线网卡工作是否正常) 新的手机是否可以连接 ...
- 10 Interesting Linux Command Line Tricks and Tips Worth Knowing
I passionately enjoy working with commands as they offer more control over a Linux system than GUIs( ...
- GUID (全局唯一标识符)
全局唯一标识符(GUID,Globally Unique Identifier)是一种由算法生成的二进制长度为128位的数字标识符.GUID主要用于在拥有多个节点.多台计算机的网络或系统中. ...
- 1369 xth 砍树
1369 xth 砍树 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 在一个凉爽的夏夜,xth 和 ...
- struts2框架的第一个程序
helloworld.jsp在base目录下 <a href="${pageContext.request.contextPath }/base/HelloWorldAction.ac ...