读书人

spring经过ApplicationContext读取Bea

发布时间: 2012-10-30 16:13:36 作者: rapoo

spring通过ApplicationContext读取Bean、message实例

1、读取Bean的应用

?

ServletContext application = getServletContext();   // 读取SPRING 容器ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(application);// 读取容器中的QUARTZ总管类org.quartz.Scheduler scheduler = (org.quartz.impl.StdScheduler)ctx.getBean("startQuertz");

?2、读取国际化的应用

Object[] obj = new Object[]{}; Locale locale = (Locale)request.getSession().getAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);ServletContext servletContext = request.getSession().getServletContext();ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);String iString = ctx.getMessage(code, obj, locale);
?

读书人网 >编程

热点推荐