spring BeanFactory加载xml配置文件示例
项目目录结构如下:

HelloWorld.java
package com.thief.demo;
public class HelloWorld {
public void sayHello() {
System.out.println("hello world!");
}
}
helloworld-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" >
<beans>
<bean id="helloworld" class="com.thief.demo.HelloWorld"/>
</beans>
Test.java
package com.thief.demo; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; public class Test { public static void main(String[] args) { DefaultListableBeanFactory beanRegistry = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanRegistry);
reader.loadBeanDefinitions("classpath:com/thief/demo/helloworld-config.xml");
BeanFactory container = (BeanFactory)beanRegistry; HelloWorld helloworld = (HelloWorld)container.getBean("helloworld");
helloworld.sayHello(); } }
spring BeanFactory加载xml配置文件示例的更多相关文章
- Spring中加载xml配置文件的六种方式
Spring中加载xml配置文件的六种方式 博客分类: Spring&EJB XMLSpringWebBeanBlog 因为目前正在从事一个项目,项目中一个需求就是所有的功能都是插件的形式装 ...
- Spring中加载xml配置文件的常用的几种方式
https://blog.csdn.net/qq877507054/article/details/62432062
- Spring加载xml配置文件的方式(BeanFactory和ApplicationContext区别)
描述 大家都知道Java读普通文件是通过Basic I/O 中的InputStream.OutStream.Reader.Writer 等实现的.在spring 框架中,它是怎样识别xml这个配置文件 ...
- Spring加载xml配置文件的方式 ApplicationContext
大家都知道Java读普通文件是通过Basic I/O 中的InputStream.OutStream.Reader.Writer 等实现的.在spring 框架中,它是怎样识别xml这个配置文件的呢? ...
- Spring加载XML配置文件
原创链接:http://www.cnblogs.com/yanqin/p/5282929.html(允许转载,但请注明原创链接) BeanFactory加载单个文件 当使用beanfactory去获取 ...
- Spring如何加载log4j配置文件
今天有朋友在群里问了这个问题,于是写了这篇文章进行整理. 问题如下: 在项目中添加了log4j.properties配置文件,并没有在Spring配置文件中配置,也没有在web.xml中配置,但是代码 ...
- Spring加载xml配置文件的方式
梳理Spring的流程 xml是最常见的spring 应用系统配置源.Spring中的几种容器都支持使用xml装配bean,包括: XmlBeanFactory,ClassPathXmlApplica ...
- spring动态加载(刷新)配置文件 [复制链接]
待验证 在程序开发时,通常会经常修改spring的配置文件,不得不重启tomcat来加载spring配,费时费力.如果能在不重启tomcat的情况下,手动动态加载spring 配置文件,动态重启读取s ...
- spring boot 加载application配置文件
这就要注意了
随机推荐
- 能上架App的GooglePlay开发者账号获取流程
googleplay 开发者账号申请流程 接到公司号召,要让我们的app走向世界,上架GooglePlay,都说天朝的Android 程序员是折翼的天使,猛然发现写了做么多年的Android,竟然不知 ...
- 让用VS2012/VS2013编写的程序在XP中顺利执行
微软为了推销自家平台,默认配置下VS2012和VS2013编写的应用程序仅仅能在Vista/Win7/Win8上执行.但幸好还保留了生成XP程序的设置项.XP和Win2003的用户还是大量存在的,我们 ...
- MongoDB系列四:解决secondary的读操作
http://blog.itpub.net/26812308/viewspace-2124660/ 在Replica sets 中的secondary节点默认是不可读的.使用Replica Sets实 ...
- PHP Warning: 的解决方法
在后台管理,用header("location:");做返回时,总是不能正常返回, Warning: Cannot modify header information - head ...
- 一起学Netty(一)之 Hello Netty
一起学Netty(一)之 Hello Netty 学习了:https://blog.csdn.net/linuu/article/details/51306480
- configure.ac:8: error: Autoconf version 2.64 or higher is required
安装Resource Agents的时候出现错误:configure.ac:9: error: Autoconf version 2.63 or higher is required.指的是autoc ...
- axis2 利用小工具cat.aar
Axis2: Web Service是现在最适合实现SOAP的技术,而Axis2是实现Web Service的一种技术框架(架构). 昨天把把菜刀脚本打包发现<>在xml会被转义,导致菜刀 ...
- android 4.0 禁用系统home键
2.2 禁用系统home键.这里不说了. 近期项目有一个需求,禁用系统的全部键.像menu, home, back.同一时候还要是想点击响应与view的弹出. 就是UI这部分要正常. back键我们自 ...
- epoll使用详解(精髓)(转)
epoll - I/O event notification facility 在linux的网络编程中,很长的时间都在使用select来做事件触发.在linux新的内核中,有了一种替换它的机制,就是 ...
- P-Called-Party-ID 头域的应用说明
P-Called-Party-ID 头域的适用场景 P-Called-Party-ID 适用于 UAS 须要知道在代理将目标改写为Contact 地址之前请求中Request-URI的目的AOR的情况 ...