spring容器
来源:互联网 发布:椰子油 炒菜 知乎 编辑:程序博客网 时间:2024/05/29 02:36
spring容器对象:
ApplicationContext 的主要实现类:
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
ApplicationContext:都支持字符串指令:
1.类路径查找 classpath: 项目中xml文件的路径
2.文件系统查找 file:系统磁盘中xml文件的路径
ClassPathXmlApplicationContext:默认是classpath
FileSystemXmlApplicationContext: 默认是file
GenericXmlApplicationContext: 默认是classpath
ConfigurableApplicationContext 扩展于 ApplicationContext,新增加两个主要方法:refresh() 和 close(),
让ApplicationContext 具有启动、刷新和关闭上下文的能力
(bean的生命周期:容器启动时调用init方法,容器调用close()方法时调用destroy())
getBean()方法:传入id返回对应的对象(Object),需要强制转换成对应的对象
没有设置id,默认id的值:包名.类名#编号
当bean中出现>=2个类实例,不知道取出的是哪个实例
可以通过类名.class获取对象,当bean中出现>=2个类实例,报错
//遍历容器中的对象名称
String[] strings=context.getBeanDefinitionNames();
for(String string:strings){
System.out.println(string);
}
ApplicationContext 的主要实现类:
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
ApplicationContext:都支持字符串指令:
1.类路径查找 classpath: 项目中xml文件的路径
2.文件系统查找 file:系统磁盘中xml文件的路径
ClassPathXmlApplicationContext:默认是classpath
FileSystemXmlApplicationContext: 默认是file
GenericXmlApplicationContext: 默认是classpath
ConfigurableApplicationContext 扩展于 ApplicationContext,新增加两个主要方法:refresh() 和 close(),
让ApplicationContext 具有启动、刷新和关闭上下文的能力
(bean的生命周期:容器启动时调用init方法,容器调用close()方法时调用destroy())
getBean()方法:传入id返回对应的对象(Object),需要强制转换成对应的对象
没有设置id,默认id的值:包名.类名#编号
当bean中出现>=2个类实例,不知道取出的是哪个实例
可以通过类名.class获取对象,当bean中出现>=2个类实例,报错
//遍历容器中的对象名称
String[] strings=context.getBeanDefinitionNames();
for(String string:strings){
System.out.println(string);
}
阅读全文
0 0
- spring容器
- Spring容器
- spring 容器
- Spring容器
- spring容器
- spring容器
- Spring容器
- spring 容器
- Spring容器
- spring容器
- Spring容器
- Spring容器
- Spring容器
- Spring容器
- Spring容器
- Spring容器
- Spring 容器
- spring容器
- 移动端实现1px的边框
- 树莓派 安装 PCL
- 【MooseFS】使用详解
- android复制粘切的实现
- JSON
- spring容器
- html/jsp针对网页history.back()之后ios系统不重新加载js的解决办法
- 第九周项目1-二叉树算法库
- 【蓝桥杯】【猴子吃桃】
- sourceinsight4.0破解教程及下载
- 私钥密钥公钥的理解
- Bose QuietControl 30无线降噪耳机
- 【第一次机房收费系统】配置工作
- qt加载word