`
Scliu123
  • 浏览: 39690 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
最近访客 更多访客>>
社区版块
存档分类
最新评论

Spring核心技术----IoC的Bean基本管理

阅读更多

BeanFactory   和    ApplicationContext

 

            org.springframework.beans.factory.BeanFactory 负责读取Bean定义文件,管理对象的加载,生成,维护Bean对象与Bean对象之间的依赖关系,负责Bean的生命周期。

             

             org.springframework.context.ApplicationContext  的基本功能与BeanFactory很相似,它也具有负责读取Bean定义文件,维护Bean之间的依赖关系等功能,除此之外ApplicationContext还提供了一个应用程序所需的更完整的框架功能,例如:

  • 提供取得资源文件(Resource file)更方便的方法;
  • 提供文字消息解析的方法;
  • 支持国际化(Internationalization ,I18N)消息;
  • ApplicationContext可以发布事件,对事件感兴趣的Bean可以接收到这些事件;

 Spring的创始人Rod Johnson建议使用ApplicationContext来取代BeanFactory,在 实现ApplicationContext的类中,最常用的大概是以下3个:

  • org.springframework.context.support.FileSystemXmlApplicationContext

         /** 可指定XML定义文件的相对路径或绝对路径来读取定义文件*/

  • org.springframework.context.support.ClassPathXmlApplicationContext

         /** 从Classpath设定路径来读取XML定义文件*/

  • org.springframework.web.context.support.XmlWebApplicationContect

       /**  在Web应用程序的文件架构中,指定相对位置来读取定义文件*/

 

 

==============

修改前一个例子的代码

-------------------------------------------------------------------------------

package only;

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

        public class SpringDemo {

                    public static void main(String[] args) {
                           ApplicationContext context=

                                              new FileSystemXmlApplicationContext("src/applicationContext.xml");
                           HelloBean hello=(HelloBean)context.getBean("helloBean");  //获得Bean对象
                           System.out.println(hello.getHelloWord()); //应用Bean对象
                    }
         }

分享到:
评论

相关推荐

    springIOC核心组件分析.vsdx

    spring-core:核心模块 依赖注入IOC和DI的最基本实现 spring-beans:Bean工厂与装配 spring-context:上下文,即IOC容器 spring-context-support:对IOC的扩展,以及IOC子容器 spring-context-indexer:类管理组件和...

    Java-Spring-SpringIoC容器-SpringIoC的学习

    Java-Spring-SpringIoC容器-SpringIoC的学习 SpringIoC容器的学习笔记 主要介绍了IoC容器工作原理以及如何配置IoC容器 通过<bean>标签和注解配置容器

    spring-aop-5.1.0.RELEASE.jar

    spring-**core**-4.3.6.RELEASE.jar :包含spring框架基本的核心工具类,spring其他组件都要用到这个包里的类,其他组件的基本核心 spring-**beans**-4.3.6.RELEASE.jar:所有应用都要用到的jar包,它包含访问配置...

    spring-framework-5.1.2.RELEASE.rar

    spring-beans-5.1.8.RELEASE.jar //配置、创建、管理Bean,负责Ioc、DI spring-context-5.1.8.RELEASE.jar //提供在基础IoC上的扩展服务 spring-expression-5.1.8.RELEASE.jar //提供对Spring表达式语言的支持

    spring-framework-5.0.4.RELEASEspring-framework-5.0.4.RELEASE

    Spring是什么呢?首先它是一个开源的项目,而且目前非常活跃...它实现了很优雅的MVC,对不同的数据访问技术提供了统一的接口,采用IOC使得可以很容易的实现bean的装配,提供了简洁的AOP并据此实现Transaction Management

    spring最小依赖包

    4) spring-beans-3.2.8.RELEASE.jar SpringIoC(依赖注入)的基础实现 5) spring-context-3.2.8.RELEASE.jar Spring提供在基础IoC功能上的扩展服务 6) spring-core-3.2.8.RELEASE.jar Spring的核心包 7) ...

    撸一撸Spring Framework-IoC-BeanDefinition(csdn)————程序.pdf

    撸一撸Spring Framework-IoC-BeanDefinition(csdn)————程序

    spring-beans-4.0.0.RELEASE.jar

    spring-beans-4.0.0.RELEASE.jar这个jar文件是所有应用都要用到的,它包含访问配置文件、创建和管理bean以及进行Inversion of Control / Dependency Injection(IoC/DI)操作相关的所有类。如果应用只需基本的IoC/DI...

    详解Spring框架---IOC装配Bean

    本篇文章主要介绍了详解Spring框架---IOC装配Bean,提供了三种方式实例化Bean,具有一定的参考价值,有兴趣的可以了解一下。

    Spring框架核心--入门适合初学者

    Spring是一个非常活跃的开源框架, 它是一个基于IOC和AOP来构架多层JavaEE系统的框架,它的主要目地是简化企业开发 Spring以一种非侵入式的方式来管理你的代码, Spring提倡”最少侵入”,这也就意味着你可以适当的时候...

    maven-spring-ioc

    spring IoC, 使用配置文件方式配置Bean的实例化和依赖注入

    spring-struts1-strust2-hibernate 核心包介绍

    这个jar文件是所有应用都要用到的,它包含访问配置文件、创建和管理bean以及进行 Inversion of Control / Dependency Injection(IoC/DI)操作相关的所有类。如果应用只需基本的IoC /DI支持,引入spring-core.jar及...

    spring Ioc bean 容器

    spring容易对于bean的配置,以及spring ioc技术的实现的讲解!

    spring-framework-3.1.0.RELEASE.zip

    容器——Spring包含并管理应用对象的配置和生命周期,在这个意义上它是一种容器,你可以配置你的每个bean如何被创建——基于一个可配置原型(prototype),你的bean可以创建一个单独的实例或者每次需要时都生成一个...

    spring IOC反射装载bean

    spring基于xml配置加载bean 的demo 了解spring的反射机制

    spring4.1核心包

    配置文件 创建和管理bean。 4.spring-context-4.1.1.RELEASE.jar 在基础IOC功能上提供扩展服务,此外还提供许多企业级服务的支持,有邮件服务、任务调度、JNDI定位,EJB集成、远程访问、缓存以及多种视图层框架的...

    08-IoC配置-bean的生命周期控制

    Spring IOC容器可以管理Bean的生命周期,允许在Bean生命周期的特定点执行定制的任务。 Spring IOC容器对Bean的生命周期进行管理的过程如下: 通过构造器或工厂方法创建Bean实例 为Bean的属性设置值和对其它Bean的...

    spring-security-4.2.5.RELEASE-source.zip

    它提供了一组可以在Spring应用上下文中配置的Bean,充分利用了Spring IoC,DI(控制反转Inversion of Control ,DI:Dependency Injection 依赖注入)和AOP(面向切面编程)功能,为应用系统提供声明式的安全访问控制...

    spring-security-samples-tutorial 源码实例

    它提供了一组可以在Spring应用上下文中配置的Bean,充分利用了Spring IoC(依赖注入,也称控制反转)和AOP(面向切面编程)功能,为应用系统提供声明式的安全访问控制功能,减少了为企业系统安全控制编写大量重复...

    B-spring-ioc-container-homework:IoC容器基础知识Spring课程

    Spring IoC容器基础作业 作业描述 阅读以下问题描述,按要求实现。 问题1 分支:p1-从这里开始 主观题:@Component已经可以支持声明一个bean了,为什么还要再弄个@Bean出来? 问题2 分支:p2-从这里开始 ...

Global site tag (gtag.js) - Google Analytics