- 讲师:刘萍萍 / 谢楠
- 课时:160h
- 价格 4580 元
特色双名师解密新课程高频考点,送国家电网教材讲义,助力一次通关
配套通关班送国网在线题库一套
方便获取Spring IoC容器中的Bean,调用方法:getBean(String name)
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class SpringtUtil {
private static SpringtUtil instance = new SpringtUtil();
private static ApplicationContext context;
public static final String spring_context_configfile = "spring.context.configfile";
public static Object getBean(String name) {
return getContext().getBean(name);
}
public static ApplicationContext getContext() {
return SpringtUtil.getInstance().context;
}
public static SpringtUtil getInstance()
{
return instance;
}
private SpringtUtil()
{
try
{
String springContextFileName =PropertiesUtil.getProperty(spring_context_configfile);
//System.out.println(springContextFileName);
context = new FileSystemXmlApplicationContext(springContextFileName);
} catch (Throwable t) {
t.printStackTrace();
}
}
public static void main(String args)
{
try {
UserService userService= (UserService)SpringtUtil.getBean("userService");
userService.test("id", "name");
} catch (Exception e) {
e.printStackTrace();
}
责编:罗莉
上一篇:一种使用RTTI的好方案
下一篇:java中的双缓冲技术
课程专业名称 |
讲师 |
课时 |
查看课程 |
---|
课程专业名称 |
讲师 |
课时 |
查看课程 |
---|
点击加载更多评论>>