获取所有bean的名字
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
WebApplicationContext ac = ContextLoaderListener.getCurrentWebApplicationContext();
//ApplicationContext ac = SpringContext.getApplicationContext();
String[] strings=ac.getBeanDefinitionNames();
System.out.println(strings.length); AutowireCapableBeanFactory beanFactory = ac.getAutowireCapableBeanFactory();
beanFactory.autowireBean(a);
String name = a.getClass().getName();
beanFactory.initializeBean(a, name);
strings=ac.getBeanDefinitionNames();
System.out.println(strings.length);
for (String string : strings) {
System.out.println(string);
}
获取所有bean的名字的更多相关文章
- spring aop切面中获取代理bean的名字以及bean
//切面中搞: Map<String , Object> map = (Map)ApplicationContextHelper.getBean(proceedingJoinPoint.g ...
- 7 -- Spring的基本用法 -- 10... 获取其他Bean的属性值;获取Field值;获取任意方法的返回值
7.10 高级依赖关系配置 组件与组件之间的耦合,采用依赖注入管理:但基本类型的成员变量值,应直接在代码中设置. Spring支持将任意方法的返回值.类或对象的Field值.其他Bean的getter ...
- 转!!spring @component 详解 默认初始化bean的名字 VNumberTask类 就是 VNumberTask
参考链接:信息来源 今天碰到一个问题,写了一个@Service的bean,类名大致为:CUser xml配置: <context:component-scan base-package=&quo ...
- spring和hibernate整合时报sessionFactory无法获取默认Bean Validation factory
Hibernate 3.6以上版本在用junit测试时会提示错误: Unable to get the default Bean Validation factory spring和hibernate ...
- mysql 获取所有的数据库名字
mysql 获取所有的数据库名字 一.如果使用的是mysqli: $con = @mysqli_connect("localhost", "root", &qu ...
- Spring-程序中获取注册bean的方式
获得spring里注册Bean的四种方法,特别是第三种方法,简单: 一:方法一(多在struts框架中)继承BaseDispatchAction import com.mas.wawacommuni ...
- SpringBoot 注册拦截器方式及拦截器如何获取spring bean实例
SpringBoot 注册拦截器时,如果用New对象的方式的话,如下: private void addTokenForMallInterceptor(InterceptorRegistry regi ...
- 配置springmvc在其他类中(spring容器外)获取注入bean
学习https://github.com/thinkgem/jeesite 今天在写JedisUtils的时候要注入JedisPool,而这个属性被设置为static,@Resource和@Autow ...
- 获取spring bean的utils
<span style="font-size:10px;">package com.record.util; import org.springframework.be ...
随机推荐
- RQNOJ 117 最佳课题选择:多重背包
题目链接:https://www.rqnoj.cn/problem/117 题意: NaCN_JDavidQ要在下个月交给老师n篇论文,论文的内容可以从m个课题中选择. 由于课题数有限,NaCN_JD ...
- java中indexOf()
Java中字符串中子串的查找共有四种方法,如下:1.int indexOf(String str) :返回第一次出现的指定子字符串在此字符串中的索引. 2.int indexOf(String str ...
- python 3 - 写一个注册的程序,账号和密码都存在文件里面
choice = input('请输入你的选择:1,注册2.删除用户3.登录') #注册 输入 账号 密码 密码确认 # #需要校验用户是否存在,两次输入的密码,是否一致,为空的情况 #账号和密码都存 ...
- cifs挂载远程文件出现 No such device or address错误
1. 参考 https://www.raspberrypi.org/forums/viewtopic.php?t=82199 找了两天看到这个文章才解决了问题. 我是之前同事在windows上挂载成功 ...
- 剑指OFFER18 判断一个二叉树的子树
public class a18_IsSubTree { public static boolean hasSubTree(TreeNode treeRoot1, TreeNode treeRoot2 ...
- Java之动态代理简介
图截于<大话设计模式> Proxy模式是常用的设计模式,其特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理消息.过滤消息.把消息转发给委托类,以及事后处理消息等. 用户可以更 ...
- zero to one (4)
复盘--天下武功唯快不破 There is no martial art is indefectible, while the fastest speed is the only way for lo ...
- RPM包构建
参考资料 https://docs-old.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html-single/RPM_Guide/i ...
- ACM学习历程——HDU 5014 Number Sequence (贪心)(2014西安网赛)
Description There is a special number sequence which has n+1 integers. For each number in sequence, ...
- [CTSC 2012] Cheat
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2806 [算法] 首先建立广义后缀自动机 注意到问题具有单调性 , 不妨对于每组询问二 ...