GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — SpringMvcStudy/SpringContextUtil.txt at master · alonebehappy/SpringMvcStudy Expand file tree/ Copy pathSpringContextUtil.txtMore file actions 35 lines (25 loc) · 1.02 KB / Copy pathSpringContextUtil.txtFile metadata and controls35 lines (25 loc) · 1.02 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 package com.alibaba.util; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; public class SpringContextUtil implements ApplicationContextAware { private static ApplicationContext applicationContext; // Spring应用上下文环境 /** * * 实现了ApplicationContextAware 接口,必须实现该方法; * * 通过传递applicationContext参数初始化成员变量applicationContext */ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { SpringContextUtil.applicationContext = applicationContext; } public static ApplicationContext getApplicationContext() { return applicationContext; } @SuppressWarnings("unchecked") public static <T> T getBean(String name) throws BeansException { return (T) applicationContext.getBean(name); } } <!-- 用于在非Spring组件中获取SpringBean --> <bean class="com.sf.service.util.SpringContextUtil"></bean> |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |