-
spring 容器外的实例如何得到spring中的bean??5
WebApplicationContextUtils. getWebApplicationContext(servletContext).getBean(beanName);???这个貌似不行,是不是因为实例没有在spring中注册,所以得不到servletContex?2009年4月14日 22:56
5个答案 按时间排序 按投票排序
-
由于用到了WebApplicationContext,你在web.xml里面需要写
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> [color=red]<listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener>[/color]
红色这段要加上
2009年4月29日 09:18
-
在web.xml配置
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
下面是在struts1.x Action中的用法WebApplicationContextUtils.getWebApplicationContext(getServlet().getServletContext()).getBean("userService");
2009年4月15日 16:58
-
使用监听器加载spring配置文件
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
使用WebApplicationContextUtils.getWebApplicationContext(servletContext).getBean("beanName");可以过去到bean实例2009年4月15日 10:13
-
这个是要你在web.xml文件中配置一个listener或servlet启动时加载spring的bean后,才能用WebApplicationContextUtils. getWebApplicationContext(servletContext).getBean(beanName);得到它的bean
2009年4月15日 01:13
相关推荐
NULL 博文链接:https://88548886.iteye.com/blog/1682243
Spring项目bean实例化代码,包括bean是如何创建的;实例化bean的三种方式,构造方法,静态工厂和实例工厂。
他们都可代表Spring容器,Spring容器是生成Bean实例的工厂,并且管理容器中的Bean。 Bean是Spring管理的基本单位,在基于Spring的Java EE应用中,所有的组件都被当成Bean处理,包括数据源、Hibernate的...
spring运行过程中动态注册bean,代码实例
Spring的三种实例化Bean的方式
本篇文章主要介绍了详解Spring中bean实例化的三种方式,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
spring管理bean应用实例代码;spring管理bean应用实例代码
Spring 实例化Bean的三种方式
主要介绍了Spring Bean的初始化和销毁,结合实例形式详细分析了Spring Bean的初始化和销毁相关配置、使用方法及操作注意事项,需要的朋友可以参考下
spring实现aop、ioc,注入,拦截demo,包含spring所需的所有jar
这篇文章将教你快速地上手使用 Spring 框架. 如果你手上有一本《Spring in Action》, 那么你最好从第三部分"Spring 在 Web 层的应用--建立 Web 层"开始看, 否则那将是一场恶梦! 首先, 我需要在你心里建立起 Spring...
Spring系列第4篇:xml中bean定义详解(-)Spring系列第5篇:创建bean实例这些方式你们都知道?Spring系列第6篇:玩转bean scope,避免跳坑里!Spring系列第7篇:依赖注入之手动注入Spring系列第8篇:自动注入...
主要介绍了Spring实战之让Bean获取Spring容器操作,结合实例形式分析了Bean获取Spring容器的相关原理、实现方法及操作注意事项,需要的朋友可以参考下
2、本工程,模拟实现Spring的IOC,将xml中配置的Bean读入到Spring容器中,并在测试用例中调用Spring容器中的bean。 3、开发环境eclipse,jdk1.6。使用第三方jar包有:jdom.jar(用于解析xml文件),junit-4.4.jar...
实例主要讲述了,Spring的Xml(list,set,map)怎样进行注入值
博客地址:https://blog.csdn.net/u010476739/article/details/76732201 spring装配bean的方式实例
1.spring中bean实例化的俩种方式 2.spring中bean的各种元素如何使用 3.spring中的bean管理 4.spring中不同类型bean的作用域 5.spring中bean的生命周期 通过我的项目,可以跟着学习SPringIoC容器和Bean管理,帮助你...
Spring-IOC实例
【课程介绍】:Spring启动时读取应用提供的Bean配置信息,在Spring容器中生成对应的Bean配置注册表,然后根据这个注册表实例化Bean,组装了Beans之间的依赖关系,为上层应用提供了一个现成的运行环境。【课程目录】...
NULL 博文链接:https://bijian1013.iteye.com/blog/2384411