`

Spring Gossip: BeanFactory、ApplicationContext

阅读更多

BeanFactory负责读取Bean定义档,管理物件的载入、生成,物件之间的关系维护,负责Bean的生命周期,对于简单的应用程式来说,使用BeanFactory就已经足够,但是若要利用到Spring在框架上的一些功能以及进阶的容器功能,则可以使用ApplicationContext,BeanFactory则通常用于一些资源有限的装置,像是行动设备。

ApplicationContext的基本功能與BeanFactory很相似,它也負責讀取Bean定義檔,維護Bean之間的關係等,然而ApplicationContext提供的一個應用程式所需的更完整的框架功能: ApplicationContext的基本功能与BeanFactory很相似,它也负责读取Bean定义档,维护Bean之间的关系等,然而ApplicationContext提供的一个应用程式所需的更完整的框架功能:

  • ApplicationContext提供取得資源檔案更方便的方法。 ApplicationContext提供取得资源档案更方便的方法。
  • ApplicationContext提供文字訊息解析的方法,並支援國際化(Internationalization, I18N)訊息。 ApplicationContext提供文字讯息解析的方法,并支援国际化(Internationalization, I18N)讯息。
  • ApplicationContext可以發佈事件,對事件感興趣的Bean可以接收到這些事件。 ApplicationContext可以发布事件,对事件感兴趣的Bean可以接收到这些事件。


Rod Johnson建議使用ApplicationContext來取代BeanFactory,在許多實作ApplicationContext的類別中,最常使用的大概是以下三個: Rod Johnson建议使用ApplicationContext来取代BeanFactory,在许多实作ApplicationContext的类别中,最常使用的大概是以下三个:

  • FileSystemXmlApplicationContext
可指定XML定義檔的相對路徑或絕對路徑來讀取定義檔。 可指定XML定义档的相对路径或绝对路径来读取定义档。
  • ClassPathXmlApplicationContext
從Classpath中來讀取XML定義檔。 从Classpath中来读取XML定义档。
  • XmlWebApplicationContext
在Web應用程式中的檔案架構中讀取定義檔。 在Web应用程式中的档案架构中读取定义档。


舉個例子來說,可以將第一個 Spring 程式中的測試程式修改為以下的內容: 举个例子来说,可以将第一个Spring程式中的测试程式修改为以下的内容:

  • SpringDemo.java
 package onlyfun.caterpillar; package onlyfun.caterpillar; 

 import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext; 
 import org.springframework.context.support.FileSystemXmlApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; 

 public class SpringDemo { public class SpringDemo { 
 public static void main(String[] args) { public static void main(String[] args) { 
 ApplicationContext context = ApplicationContext context = 
 new FileSystemXmlApplicationContext("beans-config.xml"); new FileSystemXmlApplicationContext("beans-config.xml"); 

 HelloBean hello = HelloBean hello = 
 (HelloBean) context.getBean("helloBean"); (HelloBean) context.getBean("helloBean"); 
 System.out.println(hello.getHelloWord()); 
 } 
 } 


為了能編譯與執行以上的程式,您必須將spring-context.jar加入至Classpath的設定中。 为了能编译与执行以上的程式,您必须将spring-context.jar加入至Classpath的设定中。

ApplicationContext繼承自多個介面:ApplicationEventPublisher、 HierarchicalBeanFactory、ListableBeanFactory、MessageSource、 ResourceLoader,相關的介面與使用說明,在往後的主題會一一介紹。 ApplicationContext继承自多个介面:ApplicationEventPublisher、HierarchicalBeanFactory、ListableBeanFactory、MessageSource、ResourceLoader,相关的介面与使用说明,在往后的主题会一一介绍。
ApplicationContext 

分享到:
评论

相关推荐

    Java经典问题算法大全

    2.Algorithm Gossip: 费式数列. 3. 巴斯卡三角形 4.Algorithm Gossip: 三色棋 5.Algorithm Gossip: 老鼠走迷官(一) 6.Algorithm Gossip: 老鼠走迷官(二) 7.Algorithm Gossip: 骑士走棋盘 8.Algorithm Gossip: 八...

    经典算法大全.pdf

    巴斯卡三角形 6 4.Algorithm Gossip: 三色棋 7 5.Algorithm Gossip: 老鼠走迷官(一) 9 6.Algorithm Gossip: 老鼠走迷官(二) 11 7.Algorithm Gossip: 骑士走棋盘 13 8.Algorithm Gossip: 八皇后 ...

    经典算法大全

    巴斯卡三角形4.Algorithm Gossip: 三色棋5.Algorithm Gossip: 老鼠走迷官(一6.Algorithm Gossip: 老鼠走迷官(二7.Algorithm Gossip: 骑士走棋盘8.Algorithm Gossip: 八皇后9.Algorithm Gossip: 八枚银币10....

    开源框架 Spring Gossip

    简介 Spring Inversion of Control Dependency Injection <br> 核心容器 Spring 核心容器实作了 IoC,BeanFactory 与 ApplicationContext 的运用是了解 Spring 的重点所在。 管理 Bean...

    学习spring的很好的参考资料——Spring Gossip

    此为很有人气的Gossip的学习笔记,里面深入浅出的讲解了关于spring框架的知识与学习心得,是理解spring的不可多得的好资料。 此资料为html形式,每个知识点单独列为一张html页面,阅读很方便,不需要pdf格式下的阅读...

    ACM51个经典算法大全

    老鼠走迷宫(二)7.Algorithm Gossip: 骑士走棋盘8.Algorithm Gossip: 八皇后9.Algorithm Gossip: 八枚银币10.Algorithm Gossip: 生命游戏11.Algorithm Gossip: 字串核对12.Algorithm Gossip: 双色、三色河内塔13....

    Algorithm.rar_Algorithm Gossip_gossip_gossip algorithm_gossip算法

    2.Algorithm Gossip: 费式数列 3. 巴斯卡三角形 4.Algorithm Gossip: 三色棋 5.Algorithm Gossip: 老鼠走迷官 6.Algorithm Gossip: 老鼠走迷官(二) 7.Algorithm Gossip: 骑士走棋盘 8.Algorithm Gossip: 八皇 9....

    C 语言经典算法大全

    2.Algorithm Gossip: 费式数列......................... 5 3. 巴斯卡三角形........................................ 6 4.Algorithm Gossip: 三色棋.................. 7 5.Algorithm Gossip: 老鼠走迷官(一)......

    R-gossip:分布式负载均衡效率优化算法.pdf

    #资源达人分享计划#

    camel-gossip:骆驼八卦

    草稿用法: from("gossip://<bound>:<port>/?peers=<listOfPeers>&routeIds=<listOfRouteIdsToControl>").to("controlbus:route");listOfRouteIdsToControl在此节点被提升/降级时启动/停止。 当您在需要故障转移...

    gossip:Gossip协议的Go实现

    Gossip协议的Go实现。 概述 该软件包提供了最终一致的内存中数据存储的实现。 数据存储值使用推挽式八卦协议进行交换。 // Create a gossiper g := NewGossiper("<ip>:<port>", "<unique>", "<peer>") // Add ...

    Java算法经典案列

    2.Algorithm Gossip: 费式数列 3. 巴斯卡三角形 4.Algorithm Gossip: 三色棋 6.Algorithm Gossip: 老鼠走迷官(二) 7.Algorithm Gossip: 骑士走棋盘 9.Algorithm Gossip: 八枚银币

    R-gossip:分布式负载均衡效率优化算法

    针对在分布式一致性系统中常用的gossip算法负载均衡效率较低的问题,本文在概率gossip算法(probabilistic gossip algorithm)的基础上,设计了一种寄存器gossip算法(register gossip algorithm,下文简称R-gossip...

    C语言经典算法

    非常完美的C语言经典算法 Algorithm Gossip: 2 2N+1 魔方阵 Algorithm Gossip: 4N 魔方阵 Algorithm Gossip: 奇数魔方阵 Algorithm Gossip: 上三角 下三角 对称矩阵

    99乘法表java源码-gossip:一个javalisp解析器

    gossip - yet another lisp interpreter gossip是一个lisp解释器, 语法借鉴了scheme以及common lisp, 此项目的主要目的是学习。 安装 下载源码 打包: mvn package 运行方式: java -jar your_gossip_home/gossip-1.0-...

    cc++经典算法大全.pdf

    2.AlgorithmGossip:费式数列........................................................................................................5 3.巴斯卡三角形.........................................................

    nodejs_gossip:nodejs八卦协议实现

    nodejs_八卦 nodejs八卦协议实现 nodejs 八卦.js 连接到 localhost:8080 在 chrome 中查看网络状态 控制台命令: 重启重置对等体颜色 css_color 建立网络的节点 断网示例 重建网络

    经典算法大全(各类算法解析)

    经典算法大全 各类算法解析 1.河内之塔 2.Algorithm Gossip: 费式数列 3. 巴斯卡三角形 4.Algorithm Gossip: 三色棋 5.Algorithm Gossip: 老鼠走迷官 .............

Global site tag (gtag.js) - Google Analytics