Bean配置资源获取
来源:互联网 发布:软件测试 视频 编辑:程序博客网 时间:2024/04/29 08:01
Spring查找配置文件有三种方式。前两种为xml配置文件,后一种通过将bean配置放置在类中。这三种方式查找的根节点各有不同
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
HelloWord helloWorld=(HelloWord) context.getBean("hello");
helloWord.sayHello();
HelloWord helloWorld=(HelloWord) context.getBean("hello");
helloWord.sayHello();
注:这种方式是从src目录下查找
<--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
Resource resource=new FileSystemResource("helloMessage.xml");
BeanFactory factory=new XmlBeanFactory(resource);
HelloWord helloWorld=(HelloWord)factory.getBean("hello");
String string=helloWorld.sayHello();
BeanFactory factory=new XmlBeanFactory(resource);
HelloWord helloWorld=(HelloWord)factory.getBean("hello");
String string=helloWorld.sayHello();
注:这种方式是从工程目录下查找
<--------------------------------------------------------------------------------------------------------------------------------------------------------------------->
ApplicationContext context=new AnnotationConfigApplicationContext(HelloConfig.class);
HelloWorld helloWorld=(HelloWorld) context.getBean("hello");
helloWorld.sayHello();
HelloWorld helloWorld=(HelloWorld) context.getBean("hello");
helloWorld.sayHello();
注:这种方式是从当前包目录下查找
1 0
- Bean配置资源获取
- 使用 Annotation将配置资源注入到Bean中
- (3)spring获取资源的类及获取bean的方法
- Java中获取配置/资源文件
- Java中如何获取Spring中配置的bean
- 普通的java类获取spring 的bean配置
- Spring从配置中获取bean取不到
- 解析Java中如何获取Spring中配置的bean
- Java中如何获取Spring中配置的bean
- 非注解方式获取spring bean对象以及配置值
- Bean 配置
- 配置bean
- 【Spring】 (7)加载外部资源txt,获取 当前bean名称
- 扩展Spring——使用 Annotation将配置资源注入到Bean中
- 通过上下文获取bean和通过bean工厂获取bean
- C# 获取版本号、资源文件、全局配置Settings.Settings
- Servlet获取Spring bean
- 通过ApplicationContextAware获取bean
- Fail to connect to camera service的几种原因和解决方法
- 2016前端开发技术巡礼
- TMS320F28335之默认中断系统
- IOS开发中,SVN如何恢复到某一个版本(以Cornerstone为例)
- UIAlertController详解和UINavigaton使用解析
- Bean配置资源获取
- python学习记录--字典
- linux 硬链接 软连接
- ProgressDialog
- Netty 粘包、断包解决
- TensorFlow: A System for Large-Scale Machine Learning
- CSS3--利用transform和transition属性制作扇形导航
- spring boot +WebSocket 广播式(二)
- mysql InnoDB表插入操作报duplicate entry for primary 却查询不到重复的主键