spring 获取 bean
不通过注解或者是配置文件怎么获取spring中定义的bean呢?有几个方法:
1、实现ApplicationContextAware
<bean class="com.xxx.SpringUtil"/>
SpringUtil内容如下:
public class SpringUtil implements ApplicationContextAware {
private static ApplicationContext ac;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
ac = applicationContext;
}
public static <T> T getBean(String beanName, Class<T> clazz) {
return ac.getBean(beanName, clazz);
}
}
启动的时候初始化这个类,由于这个类全部是静态方法,所以可以在项目中随便用。
spring 获取 bean的更多相关文章
- paip.spring 获取bean getBean 没有beanid的情况下
paip.spring 获取bean getBean 没有beanid的情况下 spring能自动扫描带有注解的bean文件.. 作者Attilax 艾龙, EMAIL:1466519819@q ...
- spring获取bean的时候严格区分大小写
如题:spring获取bean的时候严格区分大小写 配置文件helloservice.xml中配置: <dubbo:reference id="IInsurance" int ...
- Spring获取bean工具类,可用于在线程里面获取bean
Spring获取bean工具类,可用于在线程里面获取bean import java.util.Locale; import org.springframework.beans.BeansExcept ...
- Spring获取bean的几种方式
工作中需要对一个原本加载属性文件的工具类修改成对数据库的操作当然,ado层已经写好,但是需要从Spring中获取bean,然而,工具类并没有交给Spring来管理,所以需要通过方法获取所需要的bean ...
- Spring获取bean的一种方式
随便一百度,网上一大把,并且还不止一种.所以这里就只记录目前用的一种好了. 实现ApplicationContextAware接口 即可: import org.springframework.bea ...
- Spring 获取bean
方法一: ApplicationContext ap = new ClassPathXmlApplicationContext("applicationContext.xml"); ...
- Spring获取bean的工具类
package com.tech.jin.util; import org.springframework.context.ApplicationContext; import org.springf ...
- Spring 获取bean 几种方式
转载自: http://www.cnblogs.com/luoluoshidafu/p/5659574.html 1.读取xml文件的方式,这种在初学入门的时候比较适用 . ApplicationCo ...
- spring 获取bean的几种方式
1.读取xml文件的方式,这种在初学入门的时候比较适用 . ApplicationContext applicationContext = new ClassPathXmlApplicationCon ...
随机推荐
- 【LeetCode OJ】Balanced Binary Tree
Problem Link: http://oj.leetcode.com/problems/balanced-binary-tree/ We use a recursive auxilar funct ...
- [转]http://makefiletutorial.com/
Intro This makefile will always run. The default target is some_binary, because it is first. some_bi ...
- fastcoloredtextbox控件 看下是否解决了中文
该控件解决中文网址 未测试是否解决 想保存 http://www.dullong.com/share-a-code-can-be-highlighted-components-fastco ...
- 《JavaScript模式》第6章 代码复用模式
@by Ruth92(转载请注明出处) 第6章:代码复用模式 GoF 在其著作中提出的有关创建对象的建议原则: -- 优先使用对象组合,而不是类继承. 传统模式:使用类继承: 现代模式:"类 ...
- HC蓝牙模块测试AT指令搭建外部电路遇到的问题
按这个搭,AT指令烧不进去,两块板两次都不行. 这是我的底板(比较混乱的万能版) 第一次短路了,VCC和GND在板子下面连起来了,肉眼当然看不见,吹下来重新焊就好了. 第二次,txdrxd与usb转T ...
- qsort函数用法【转】
qsort函数用法 qsort 功 能: 使用快速排序例程进行排序 用 法: void qsort(void *base, int nelem, int width, int (*fcmp)(con ...
- SQLite手工注入方法小结
SQLite 官网下载:www.sqlite.org/download.html sqlite管理工具:http://www.yunqa.de/delphi/products/sqlitespy/in ...
- python语言switch-case
初学python语言,竟然很久才发现python没有switch-case语句,查看官方文档说是可以用if-elseif-elseif....代替. 讲真,这都不是问题.不就是一个条件判断吗.用if- ...
- ✡ leetcode 157. Read N Characters Given Read4 利用read4实现read --------- java
The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...
- CF 628A --- Tennis Tournament --- 水题
CF 628A 题目大意:给定n,b,p,其中n为进行比赛的人数,b为每场进行比赛的每一位运动员需要的水的数量, p为整个赛程提供给每位运动员的毛巾数量, 每次在剩余的n人数中,挑选2^k=m(m & ...