Spring在3.1版本后的bean获取方法的改变

xml配置不变,如下

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"><bean id="test3" class="org.springframework.tests.sample.beans.TestBean" scope="prototype"><property name="name"><value>custom</value></property><property name="age"><value>25</value></property></bean></beans>

  

3.0版之前

获取bean的方式是用   XmlBeanFactory

	@Testpublic void beanTest(){Resource rs2 = new ClassPathResource("test.xml",AATest.class);BeanFactory bf = new XmlBeanFactory(rs2);TestBean tb2 = (TestBean)bf.getBean("test3");assertEquals("custom",tb2.getName());}

  

3.1版本之后,因为某些原因,XmlBeanFactory被抛弃了,如果再用的化,会显示

The type XmlBeanFactory is deprecated

源码里的测试方法里获取bean的方法如下

@Testpublic void beanTest2(){Resource rs = new ClassPathResource("test.xml",AATest.class);;DefaultListableBeanFactory grandParent = new DefaultListableBeanFactory();new XmlBeanDefinitionReader(grandParent).loadBeanDefinitions(rs);TestBean tb = (TestBean) grandParent.getBean("test3");assertEquals("custom",tb.getName());}

 当然,也可以像下面这样调用

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/qst/chapter08/bean.xml");Book book = (Book) context.getBean("book");

  

至于被抛弃的原因,如下

/*** Convenience extension of {@link DefaultListableBeanFactory} that reads bean definitions* from an XML document. Delegates to {@link XmlBeanDefinitionReader} underneath; effectively* equivalent to using an XmlBeanDefinitionReader with a DefaultListableBeanFactory.** <p>The structure, element and attribute names of the required XML document* are hard-coded in this class. (Of course a transform could be run if necessary* to produce this format). "beans" doesn't need to be the root element of the XML* document: This class will parse all bean definition elements in the XML file.** <p>This class registers each bean definition with the {@link DefaultListableBeanFactory}* superclass, and relies on the latter's implementation of the {@link BeanFactory} interface.* It supports singletons, prototypes, and references to either of these kinds of bean.* See {@code "spring-beans-3.x.xsd"} (or historically, {@code "spring-beans-2.0.dtd"}) for* details on options and configuration style.** <p><b>For advanced needs, consider using a {@link DefaultListableBeanFactory} with* an {@link XmlBeanDefinitionReader}.</b> The latter allows for reading from multiple XML* resources and is highly configurable in its actual XML parsing behavior.** @author Rod Johnson* @author Juergen Hoeller* @author Chris Beams* @since 15 April 2001* @see org.springframework.beans.factory.support.DefaultListableBeanFactory* @see XmlBeanDefinitionReader* @deprecated as of Spring 3.1 in favor of {@link DefaultListableBeanFactory} and* {@link XmlBeanDefinitionReader}*/
@Deprecated
@SuppressWarnings({"serial", "all"})
public class XmlBeanFactory extends DefaultListableBeanFactory {
//code...}

  

 

 

转载于:https://www.cnblogs.com/lakeslove/p/7134191.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/254106.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

使用halcon选择点拟合成直线求直线角度

原图 源码 read_image (Image, 0.bmp) dev_clear_window () dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle) dev_display (Image)binary_threshold (Image, Region, max_separability, dark, UsedThreshold) connection (Region, ConnectedRegions) select_s…

Linux网络/firewalld和netfilter/netfilter/iptables语法

为什么80%的码农都做不了架构师&#xff1f;>>> linux网络相关 查看网卡网络信息 ifconfig 命令查看网卡网络信息&#xff0c;比如ip、网关、子网掩码等&#xff0c;但是安装centos7的版本或者某些未知原因&#xff0c;此命令提示找不到&#xff0c;我们可以使用Yu…

Chrome开发者工具详解(4)-Profiles面板

Chrome开发者工具详解(4)-Profiles面板 如果上篇中的Timeline面板所提供的信息不能满足你的要求&#xff0c;你可以使用Profiles面板&#xff0c;利用这个面板你可以追踪网页程序的内存泄漏问题&#xff0c;进一步提升程序的JavaScript执行性能。 概述 当前使用的Chrome最新版为…

etcd raft library设计原理和使用

早在2013年11月份&#xff0c;在raft论文还只能在网上下载到草稿版时&#xff0c;我曾经写过一篇blog对其进行简要分析。4年过去了&#xff0c;各种raft协议的讲解铺天盖地&#xff0c;raft也确实得到了广泛的应用。其中最知名的应用莫过于etcd。etcd将raft协议本身实现为一个l…

halcon通过点拟合圆形,鼠标选点

原图 源码 read_image (Image, 0.bmp) dev_clear_window () dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle) dev_display (Image)binary_threshold (Image, Region, max_separability, dark, UsedThreshold) connection (Region, ConnectedRegions) select_s…

JDBC事务--软件开发三层架构--ThreadLocal

JDBC事务--软件开发三层架构--ThreadLocal 一.JDBC事务 1.概述: 事务是指逻辑上的一组操作!这一组操作,通常认为是一个整体,不可拆分! 特点:同生共死;事务内的这一组操作要么全部成功,要么全部失败! 作用:保证逻辑操作的完整性,安全性! 2.使用(3种方式) 1)面向数据库,使用S…

LINUX多播编程

一.单播&#xff0c;广播和多播 1.单播用于两个主机之间的端对端通信&#xff0c;广播用于一个主机对整个局域网上所有主机上的数据通信。单播和广播是两个极端&#xff0c;要么对一个主机进行通信&#xff0c;要么对整个局域网上的主机进行通信。实际情况下&#xff0c;经常需…

cas单点登录搭建

Cas Server下载&#xff1a;http://developer.jasig.org/cas/ Cas Client下载&#xff1a;http://developer.jasig.org/cas-clients/ 测试环境&#xff1a; jdk&#xff1a;java version "1.8.0_60" tomcat&#xff1a;apache-tomcat-7.0.65 mysql&#xff1a;mysql5…

新CIO:Mark Schwartz认为的领先IT

美国公民及移民服务局前任CIO&#xff0c;现任AWS企业战略师Mark Schwartz在伦敦举行的DevOps企业峰会上介绍了什么是领先的IT。\\Schwartz介绍说&#xff0c;老旧、传统的模型将业务和IT完全分开&#xff0c;他又提出了一种新的模型&#xff0c;在这种模型中&#xff0c;CIO担…

689D Magic Odd Square 奇数幻方

1 奇数阶幻方构造法 (1) 将1放在第一行中间一列; (2) 从2开始直到nn止各数依次按下列规则存放&#xff1a;按 45方向行走&#xff0c;向右上&#xff0c;即每一个数存放的行比前一个数的行数减1&#xff0c;列数加1 (3) 如果行列范围超出矩阵范围&#xff0c;则回绕。例如1在第…

Java单例的常见形式

2019独角兽企业重金招聘Python工程师标准>>> Java单例的常见形式 本文目的&#xff1a;总结Java中的单例模式 本文定位&#xff1a;学习笔记 学习过程记录&#xff0c;加深理解&#xff0c;便于回顾。也希望能给学习的同学一些灵感 一、非延迟加载单例类 public cla…

运动控制卡的基类函数与实现例子

基类 namespace MotionCardDll {public abstract class IMotionCard{public Int32 m_Mode;public Int32 m_BoardId;//Card 号public Int32 m_Card_name;public Int32 m_StartAxisID

U-Boot启动过程完全分析

1.1 U-Boot 工作过程 U-Boot启动内核的过程可以分为两个阶段&#xff0c;两个阶段的功能如下&#xff1a; &#xff08;1&#xff09;第一阶段的功能 硬件设备初始化 加载U-Boot第二阶段代码到RAM空间 设置好栈 跳转到第二阶段代码入口 &#xff08;2&#x…

CJOJ 2171 火车站开饭店(树型动态规划)

CJOJ 2171 火车站开饭店&#xff08;树型动态规划&#xff09; Description 政府邀请了你在火车站开饭店&#xff0c;但不允许同时在两个相连的火车站开。任意两个火车站有且只有一条路径&#xff0c;每个火车站最多有 50 个和它相连接的火车站。 告诉你每个火车站的利润&#…

JavaWeb总结(十五)

AJAX&#xff08;Asynchronous JavaScript and XML&#xff08;异步的 JavaScript 和 XML&#xff09;&#xff09; AJAX的作用是什么&#xff1f; 在无需重新加载整个网页的情况下&#xff0c;能够更新部分网页的技术 是一种用于创建快速动态网页的技术 通过在后台与服务器进行…

工业相机基类与实现

基类 namespace Cameron {//相机参数public struct CamPara{public int DeviceID; //设备描述public string Name;public int WorkMode; //工作类型,0为连续模式,1为触发模式public float Expours

物联网技术周报第 143 期: Unity 3D 和 Arduino 打造虚拟现实飞行器

新闻 \\\\t《西门子、阿里云签约助力中国工业物联网发展》德国工业集团西门子和中国阿里巴巴集团旗下的云计算公司阿里云&#xff19;日在柏林签署备忘录&#xff0c;共同推进中国工业物联网发展。根据备忘录内容&#xff0c;西门子和阿里云将发挥各自技术和行业优势&#xff…

不同平台下 sleep区别用法

应用程序&#xff1a; #include <syswait.h> usleep(n) //n微秒 Sleep&#xff08;n&#xff09;//n毫秒 sleep&#xff08;n&#xff09;//n秒 驱动程序&#xff1a; #include <linux/delay.h> mdelay(n) //微秒milliseconds 其实现 #ifdef notdef #define mdelay…

各视频、各音频之间格式任意玩弄(图文详解)

写在前面说的话 在这里&#xff0c;记录下来&#xff0c;是为了方便以后偶尔所制作所需和你们前来的浏览学习。 学会&#xff0c;玩弄一些视频和音频的软件&#xff0c;只有好处没有害处。同时&#xff0c;也不需很多时间&#xff0c;练练手罢了。也是方便自己所用吧&#xff0…

oracle 如何查看日志?

2019独角兽企业重金招聘Python工程师标准>>> Oracle日志查看一&#xff0e;Oracle日志的路径&#xff1a;登录&#xff1a;sqlplus "/as sysdba"查看路径&#xff1a;SQL> select * from v$logfile;SQL> select * from v$logfile;(#日志文件路径)二…