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配置文件
这就要注意了
随机推荐
- php设计模式之解释器模式
解释器设计模式用于分析一个实体的关键元素,并且针对每个元素都提供自己的解释或相应的动作. <?php /** * 解释器模式 */ class User { protected $_userna ...
- Tomcat:Java Web服务器配置详解
一.Tomcat概述 1.tomcat简介 tomcat是基于JDK的web服务器,其能运行Servlet和JSP规范总.Tomcat 5支持最新的Servlet 2.4 和JSP 2.0规范.实际上 ...
- 2017.10.13 git提交时忽略不必要的文件或文件夹
参考来自:git学习六:git提交忽略不必要的文件或文件夹 1.应用场景 创建maven项目,使用git提交,有时需要忽略不必要的文件或文件夹,只保留一些基本. 例如如下截图,实际开发中我们只需提交: ...
- 2017.7.10 Redis报错:DENIED Redis is running in protected mode
参考来自: java 客户端链接不上redis解决方案 DENIED Redis is running in protected mode 完整错误信息: Caused by: redis.clien ...
- Elasticsearch教程(三),IK分词器安装 (极速版)
如果只想快速安装IK,本教程管用.下面看经过. 简介: 下面讲有我已经打包并且编辑过的zip包,你可以在下面下载即可. 当前讲解的IK分词器 包的 version 为1.8. 一.下载zip包. 下面 ...
- 什么是ICE (Internet Communications Engine)
http://user.qzone.qq.com/77811970 直接在google上搜索ICE,出来的结果并不多,所以很多人就认为ICE是个神秘的东西,其实,国内已经有很多大型应用在使用ICE了. ...
- Beautiful Soup 4.4.0 基本使用方法
Beautiful Soup 4.4.0 基本使用方法Beautiful Soup 安装 pip install beautifulsoup4 标准库有html.parser解析器但速度不是很快一般 ...
- es6 - filter for-chrome
'use strict'; let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]; // 除去取余2的 - es6 let es5OddNumbers = numbers ...
- python 奇技淫巧
列表内部的字典的value进行排序 li = [{a:1,b:2,c:3,d:4},{e:5,f:6,g:7,h:8}] li = [{"day":2},{"day&qu ...
- react-native 项目实战 -- 新闻客户端(2) -- 完善TabBar
1.创建 drawable-xxhdpi 文件夹,保存 TabBar 的 icon图标 android -- app -- src -- main -- res -- drawab ...