zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Spring getBeanNamesForType方法:通过类型获取Bean名称

Spring方法 获取 类型 通过 名称 bean
2023-06-13 09:12:00 时间
该方法用于获取 Spring 容器中指定类型的所有 JavaBean 的名称。

语法:

getBeanNamesForType(Class type)

参数说明:


public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext( appContext.xml //加载appContext.xml文件 String[] beanNames = context.getBeanNamesForType(Date.class); //返回所有JavaBean的名称 for(String name:beanNames){ System.out.println( JavaBean名称: +name); }

22973.html

javaspring