springmvc获取bean
1、普通注解方式获取
2、springcontextholder获取
ChatHistoryService chatHistoryService = SpringContextHolder.getBean("chatHistoryService");
3、初始化时保存applicationcontext
ApplicationContext ac = new FileSystemXmlApplicationContext("applicationContext.xml");
ac.getBean("beanId");
4、通过工具类获取去applicationcontext
ApplicationContext ac1 = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContext sc);
ApplicationContext ac2 = WebApplicationContextUtils.getWebApplicationContext(ServletContext sc);
ac1.getBean("beanId");
ac2.getBean("beanId");
5、通过contextLoader获取
WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
wac.getBean(beanID)
springmvc获取bean的更多相关文章
- JAVA中SpringMVC获取bean方法,在工具类(utils)注入service
有时候我们会出现无法用注解 @Autowired 注入bean的情况,这个时候可以 通过contextLoader获取 WebApplicationContext ctx = ContextLoade ...
- SpringMVC获取参数的几种方式
前言: 年末了,忙了一年了却发现系统的整理的东西很少,一些基础的东西都未做整理,这里就将它随便整理一下,增加一些印象,当然在网上看到一些好的资料也会整理下来以备后用.今天整理一下springMVC获取 ...
- SpringMVC获取HttpClient 请求的数据
package com.nnk.upstream.controller;import org.springframework.util.StreamUtils;import javax.servlet ...
- 使用spring手动获取Bean的时候,不能强转回它自己。
这个问题好像有点长,描述一下: 就是通过类名的方式获取Bean后,得到一个Object对象,但是这个Object不能再强转回Bean了.抛出的异常时类型转换异常. java.lang.ClassCa ...
- 从Spring容器中获取Bean。ApplicationContextAware
引言:我们从几个方面有逻辑的讲述如何从Spring容器中获取Bean.(新手勿喷) 1.我们的目的是什么? 2.方法是什么(可变的细节)? 3.方法的原理是什么(不变的本质)? 1.我们的目的是什么? ...
- [原创]java WEB学习笔记98:Spring学习---Spring Bean配置及相关细节:如何在配置bean,Spring容器(BeanFactory,ApplicationContext),如何获取bean,属性赋值(属性注入,构造器注入),配置bean细节(字面值,包含特殊字符,引用bean,null值,集合属性list map propert),util 和p 命名空间
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- 【Spring】初始化Spring IoC容器(非Web应用),并获取Bean
参考文章 Introduction to the Spring IoC container and beans BeanFactory 和ApplicationContext(Bean工厂和应用上下文 ...
- paip.spring 获取bean getBean 没有beanid的情况下
paip.spring 获取bean getBean 没有beanid的情况下 spring能自动扫描带有注解的bean文件.. 作者Attilax 艾龙, EMAIL:1466519819@q ...
- spring源码 — 二、从容器中获取Bean
getBean 上一节中说明了容器的初始化,也就是把Bean的定义GenericBeanDefinition放到了容器中,但是并没有初始化这些Bean.那么Bean什么时候会初始化呢? 在程序第一个主 ...
随机推荐
- WebService远程调用(命令行调用)
远程调用webservice 方法, 通过wsdl命令,生成webservice 对应asmx 文件的对应类(cs文件),然后将此cs文件引用到当前项目中,项目其他地方需要调用webservice方法 ...
- Redis异构集群数据在线迁移工具Redis-Migrate-Tool【转】
摘要:Redis-Migrate-Tool(后面都简称RMT),是唯品会开源的redis数据迁移工具,主要用于异构redis集群间的数据在线迁移,即数据迁移过程中源集群仍可以正常接受业务读写请求,无业 ...
- windows系统添加服务命令
管理员身份进入cmd sc create TestSvr binPath= D:\Program Files\test.exe start= auto
- CodeForces 732B Cormen — The Best Friend Of a Man
B. Cormen - The Best Friend Of a Man time limit per test 1 second memory limit per test 256 megabyte ...
- Code Forces 645C Enduring Exodus
C. Enduring Exodus time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...
- tcpdump linux抓http请求头
sudo tcpdump -i eth0 port 80 -s 1024 -l -A
- <2014 10 01> 数学基础 Wikipedia
数学基础 数学上,数学基础一词有时候用于数学的特定领域,例如数理逻辑,公理化集合论,证明论,模型论,和递归论.但是寻求数学的基础也是数学哲学的中心问题:在什么终极基础上命题可以称为真? 目前占统治地位 ...
- flask_sqlaichemy的json字段
https://segmentfault.com/q/1010000009304667/a-1020000009404847
- python基础-第六篇-6.2模块
python之强大,就是因为它其提供的模块全面,模块的知识点不仅多,而且零散---一个字!错综复杂 没办法,二八原则抓重点咯!只要抓住那些以后常用开发的方法就可以了,哪些是常用的?往下看--找答案~ ...
- Linux系统内核参数优化
Linux服务器内核参数优化 cat >> /etc/sysctl.conf << EOF # kernel optimization net.ipv4.tcp_fin_tim ...