`

通过WebApplicationContextUtils工具类获取ApplicationContext对象.

 
阅读更多

通过WebApplicationContextUtils工具类获取ApplicationContext对象.

 

只需要传入application对象即可.

如果是struts2中通过如下方式获取application对象:

ServletContext application = ServletActionContext.getRequest().getSession().getServletContext();
		

 

 

以下是获取applicationContext对象;

ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application);
UserDao bd = (UserDao)context.getBean(spring中配置bean ID的名称);

 

分享到:
评论
1 楼 honey_fansy 2014-07-27  
不错~THX

相关推荐

    applicationContext.xml

    applicationContext.xml

    spring+hibernate+osworkflow

    ApplicationContext cxt = WebApplicationContextUtils.getWebApplicationContext(this.getServletConfig().getServletContext()); Workflow wf = (Workflow)cxt.getBean("workflow"); 用osworkflow自带的designer把...

    ssh-整合资料

    可以通过 WebApplicationContextUtils.getWebApplicationContext(ServletActionContext.getServletContext()); 来获取

    在action以外的地方获取dao

    ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(); 或者 ApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(); 这是在action以外的地方拿...

    ssh(structs,spring,hibernate)框架中的上传下载

     其中第16行通过类路径的映射方式,将sshfile.model类包目录下的所有领域对象的映射文件装载进来,在本文的例子里,它将装载进Tfile.hbm.xml映射文件。如果有多个映射文件需要声明,使用类路径映射方式显然比直接...

    Spring.html

    Spring IOC 控制反转:把创建对象的权利交给Spring 创建对象 1.... 2.... 3.... 管理对象 ... 对象关系DI ...在Servlet中使用WebApplicationContextUtils获取容器对象 5.使用容器对象去获取Service对象

    JSP 获取Spring 注入对象示例

    @ page import=org.springframework.context.ApplicationContext%> ServletContext sc = this.getServletConfig().getServletContext(); ApplicationContext ac2 = WebApplicationContextUtils.get...

    +Flex+集成到+Java+EE+应用程序的最佳实践(完整源代码)

    ApplicationContext appContext = WebApplicationContextUtils. getRequiredWebApplicationContext( FlexContext.getServletConfig().getServletContext() ); String beanName = getSource(); try { log...

    spring-web-2.5.jar

    org.springframework.web.context.support.WebApplicationContextUtils.class org.springframework.web.context.support.WebApplicationObjectSupport.class org.springframework.web.context.support....

    将 Flex 集成到 Java EE 应用程序的最佳实践(完整源代码)

    ApplicationContext appContext = WebApplicationContextUtils. getRequiredWebApplicationContext( FlexContext.getServletConfig().getServletContext() ); String beanName = getSource(); try { ...

    spring源代码解析

    代码解析2,部分摘抄 简单的说,在web容器中,通过ServletContext为Spring的IOC容器提供宿主环境,对应的...任何需要访问该ApplicationContext的应用程序代码都可以从WebApplicationContextUtils类的静态方法来得到:

    商场VIP消费查询系统源代码

    一、课程安排 VIP客户查询 ... WebApplicationContextUtils工具类的使用 三、录入VIP客户 关键技术点: AO封装 参数验证 UUID生成 用户输入保留 UTF-8字符编码过滤器配置 四、VIP客户管理 关键技术点:

    spring+springmvc+mybatis的整合

    WebApplicationContext acc = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext()); ls = (LoginService) acc.getBean("MyService"); 而讲义上的实现: [java] view ...

    SPRING API 2.0.CHM

    ApplicationContext ApplicationContextAware ApplicationContextAwareProcessor ApplicationContextException ApplicationEvent ApplicationEventMulticaster ApplicationEventPublisher ...

    Java的过滤器与拦截器的区别.docx

    4 WebApplicationContextUtils.registerEnvironmentBeans(getBeanFactory(), servletContext); 5 //getServletContextInitializerBeans()这个方法进开始进行解析并添加filter过滤器 了 6 for ...

Global site tag (gtag.js) - Google Analytics