Spring之通过servlet获取托管的对象
来源:互联网 发布:js下载文件进度条 编辑:程序博客网 时间:2024/05/21 11:21
GetSpringBeanServlet的源码:
import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import org.springframework.web.context.WebApplicationContext;import org.springframework.web.context.support.WebApplicationContextUtils;public class GetSpringBeanServlet extends HttpServlet {private static final long serialVersionUID = -7078431934500337880L;private static WebApplicationContext context;public void init() throws ServletException {context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());}public static Object getBean(String id) {Object bean = context.getBean(id);return bean;}}
web.xml的配置:
<servlet>
<servlet-name>getSpringBeanServlet</servlet-name>
<servlet-class>com.cfstc.servlet.GetSpringBeanServlet</servlet-class>
<load-on-startup>4</load-on-startup>
</servlet>
*不需要配置mapping!
页面中的调用:
VoteService voteService = (VoteService)GetSpringBeanServlet.getBean("voteService");
/**直接可以调用voteService中的方法就可以啦**/
PagerModel wyvote1 = voteService.listDraftParam(1, user.getAgentId(), new HashMap(), "1");
- Spring之通过servlet获取托管的对象
- 非spring托管对象如何获取到spring托管对象
- Servlet 获取 Spring 中的对象
- Servlet中获取spring bean的管理对象
- HttpServlet获取Spring中托管的bean
- 通过ServletConfig对象获取Servlet配置参数
- 通过ServletConfig对象获取Servlet配置参数
- 普通javaBean如何获取到spring托管对象
- 在servlet中获取spring Bean对象
- Spring中ApplicationContextAware实现获取bean的工具类,在servlet中通过servletContext获取application
- Servlet:Servlet与JSP九大内置对象的对应关系以及通过Servlet获取表单数据
- 通过Spring注入,获取Service对象实例
- spring 托管 工厂创建对象
- spring servlet之注入bean对象
- 通过ServletConfig获取Servlet的初始化参数
- 如何通过Spring获取到Hibernate的Configuration对象以及Table,Column对象
- 通过Spring实现servlet的复用
- 在服务器启动时servlet中获取spring 的bean对象
- 金XX项目总结
- Everything研究之读取NTFS下的USN日志文件(1)
- jxl 自定义背景颜色——十六进制转化为Colour
- 五分钟solr4.5教程(搭建、运行)
- jni开发 - 使用Memory Analyzer tool(MAT)分析内存泄漏(三)
- Spring之通过servlet获取托管的对象
- 从mysql数据库中导入数据到solr4.5
- 关于scanf和gets函数共用时出现的一些问题的解释
- Java过滤html标签
- 一天精通Linux基本操作篇
- Log4J 配置之以日期为文件名的日志
- Jsp验证码的制作
- 《Effective C++》学习笔记条款04 确定对象被使用前被初始化
- 利用百度地图api开发的应用实例