/** 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的更多相关文章

  1. java SpringUtil获取bean

    package com.whaty.framework.common.spring; import java.io.PrintStream; import org.springframework.be ...

  2. Tomcat shutdown执行后无法退出进程问题排查及解决

    问题定位及排查 上周无意中调试程序在Linux上ps -ef|grep tomcat发现有许多tomcat的进程,当时因为没有影响系统运行就没当回事.而且我内心总觉得这可能是tomcat像nginx一 ...

  3. shiro权限管理框架与springmvc整合

    shiro是apache下的一个项目,和spring security类似,用于用户权限的管理‘ 但从易用性和学习成本上考虑,shiro更具优势,同时shiro支持和很多接口集成 用户及权限管理是众多 ...

  4. maven-sprigmvc-mybatis配置

    pom.xml配置 <?xml version="1.0"?> <project xsi:schemaLocation="http://maven.ap ...

  5. webService学习之路(二):springMVC集成CXF快速发布webService

    继上一篇webService入门之后,http://www.cnblogs.com/xiaochangwei/p/4969448.html ,现在我将我周六在家研究的结果公布出来 本次集成是基于之前已 ...

  6. shiro在springmvc里面的集成使用【转】

    <dependency> <groupId>commons-collections</groupId> <artifactId>commons-coll ...

  7. 基于Spring+SpringMVC+Mybatis的Web系统搭建

    系统搭建的配置大同小异,本文在前人的基础上做了些许的改动,重写数据库,增加依据权限的动态菜单的实现,也增加了后台返回json格式数据的配置,详细参见完整源码. 主要的后端架构:Spring+Sprin ...

  8. [Java] Spring + SpringMVC + Maven + JUnit 搭建

    示例项目下载: https://github.com/yangyxd/SpringDemo 利用前面 SpringMVC 项目的配置方式,完成初步的项目创建.下面只讲一些不同之处. 传送门: [Jav ...

  9. Spring Data JPA 学习记录1 -- 单向1:N关联的一些问题

    开新坑 开新坑了(笑)....公司项目使用的是Spring Data JPA做持久化框架....学习了一段时间以后发现了一点值得注意的小问题.....与大家分享 主要是针对1:N单向关联产生的一系列问 ...

随机推荐

  1. 【IT名人堂】何云飞:阿里云数据库的架构演进之路

    [IT名人堂]何云飞:阿里云数据库的架构演进之路 原文转载自:IT168 ​ 如果说淘宝革了零售的命,那么DT革了企业IT消费的命.在阿里巴巴看来,DT时代,企业IT消费的模式变成了“云服务+数据”, ...

  2. DWZ框架Ajax无刷新表单提交处理流程

    DWZ框架Ajax无刷新表单提交处理流程是: 1.       ajax表单提交给服务器 2.       服务器返回一个固定格式json结构 3.       js会调函数根据这个json数据做相应 ...

  3. 51nod 平均数(二分+树状数组)

    题目链接: 平均数 基准时间限制:4 秒 空间限制:131072 KB 分值: 80 LYK有一个长度为n的序列a. 他最近在研究平均数. 他甚至想知道所有区间的平均数,但是区间数目实在太多了. 为了 ...

  4. android目录

    2013-09-121.activity生命周期 activity生命周期2 widget http://blog.csdn.net/xiang_j2ee/article/details/727564 ...

  5. 实现多个UIView之间切换的动画效果

    @interface RootViewController (){ UIView *view1; UIView *view2; int flag; } @end @implementation Roo ...

  6. Tensorflow之安装

    1.fellow the instruction of https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/ge ...

  7. css+js 控制幻灯片效果

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. PHP JS判断浏览器,微信浏览器

      微信内置浏览器的 User Agent 如何判断微信内置浏览器,首先需要获取微信内置浏览器的User Agent,经过在 iPhone 上微信的浏览器的检测,它的 User Agent 是: Mo ...

  9. 调用支付宝PHP接口API实现在线即时支付功能(UTF-8编码)

    这次在项目中要实现订单功能,所以要完成在线支付,在线支付一般有网银支付和第三方支付(支付宝.paypal等)这两种途径,未简单起见,先完成支付宝在线支付功能,由于项目基于Yii框架,且使用UTF-8编 ...

  10. Shell指令

    Shell指令 1.Shell原理图 2.Shell指令的基本语法 Shell指令 Shell –选项 参数 Shell –选项 Shell参数 3.常用的Shell指令 1)ls指令:显示文件信息 ...