web项目( spring )启动后,SpringContextUtils的applicationContext属性会自动初始化(不必 new ClassPathXmlApplicationContext("applicationContext.xml")),于是可以自行编写一些静态方法从 applicationContext 中获取bean了。
package org.springside.modules.utils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class SpringContextUtils
implements ApplicationContextAware
{
private static ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext context)
{
applicationContext = context;
}
public static ApplicationContext getApplicationContext()
{
if (applicationContext == null)
throw new IllegalStateException("applicaitonContext未注入,请在applicationContext.xml中定义SpringContextUtil");
return applicationContext;
}
public static <T> T getBean(String name)
{
return applicationContext.getBean(name);
}
}
<bean id="springContextUtils" class="org.springside.modules.utils.SpringContextUtils" />
分享到:
相关推荐
springside3文档资料收录 calvin,游侠
SpringSide3框架,SpringSide3框架SpringSide3框架SpringSide3框架
springside3-core-3.2.2
springside3-core-3.3.4.jar,springside的3.3.4版本。
springside3的jar包,并附属源码
找了很久:包里包含以下2个文件;csdn上的那个只有一个extension; springside3-core-3.3.4.jar springside3-extension-3.3.4.jar
springside3-extension-3.3.4.jar
springside3-core-3.3.4.jar
springside3-core-3.3.4.jar
springside3-core-3.0.4.jar
springside3与传统ssh区别: 1.1 数据库设计 1.2 entity 对象 1.3 dao对象 1.4 manager对象 1.5 action 对象 .......................
SpringSide3开发环境mini-web项目_3 一共三个压缩包: http://download.csdn.net/source/1725011 http://download.csdn.net/source/1725015 http://download.csdn.net/source/1725311
springside
springside3-core-3.0.4 源码
springside3-core-3.3.4-sources.jar
springside3-core-3.3.0.jar