Spring(3.2.3) - Beans(1): Spring 容器
BeanFactory & ApplicationContext
org.springframework.beans.factory.BeanFactory 是最基本的 Spring 容器接口,它提供了管理 Bean 的一些基本功能。 BeanFactory 接口包含如下几个基本方法:
Object getBean(String name) throws BeansException;
<T> T getBean(String name, Class<T> requiredType) throws BeansException;
boolean containsBean(String name);
Class<?> getType(String name) throws NoSuchBeanDefinitionException;
org.springframework.context.ApplicationContext 是 org.springframework.beans.factory.BeanFactory 的子接口,除了提供 BeanFactory 所支持的功能,ApplicationContext 还提供了一些额外的功能,如国际化支持、事件机制、资源访问等。
Spring 配置文件的基本结构
<?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-3.0.xsd"> <bean id="..." class="..." >
<property name="..." value="..." />
<property name="..." ref="..." />
</bean> </beans>
实例化容器
按文件系统路径加载配置文件:
ApplicationContext appCtx = new FileSystemXmlApplicationContext("src/applicationContext.xml");
按类路径加载配置多件:
ApplicationContext appCtx = new ClassPathXmlApplicationContext("applicationContext.xml");
加载多个配置文件:
ApplicationContext appCtx = new ClassPathXmlApplicationContext(new String[] {"services.xml", "daos.xml"});
使用 Spring 容器
ExampleBean example = appCtx.getBean("example", ExampleBean.class);
Spring(3.2.3) - Beans(1): Spring 容器的更多相关文章
- Spring Framework------>version4.3.5.RELAESE----->Reference Documentation学习心得----->关于spring framework中的beans
Spring framework中的beans 1.概述 bean其实就是各个类实例化后的对象,即objects spring framework的IOC容器所管理的基本单元就是bean spring ...
- 译:Spring框架参考文档之IoC容器(未完成)
6. IoC容器 6.1 Spring IoC容器和bean介绍 这一章节介绍了Spring框架的控制反转(IoC)实现的原理.IoC也被称作依赖注入(DI).It is a process wher ...
- 监听器如何获取Spring配置文件(加载生成Spring容器)
Spring容器是生成Bean的工厂,我们在做项目的时候,会用到监听器去获取spring的配置文件,然后从中拿出我们需要的bean出来,比如做网站首页,假设商品的后台业务逻辑都做好了,我们需要创建一个 ...
- Spring源码学习(6)——容器的功能扩展
之前的随笔中借BeanFactory介绍了bean的解析和加载的完整过程,实际上,除了BeanFactory,spring还提供了一种功能更加强大的容器:ApplicationContext Appl ...
- 7 -- Spring的基本用法 -- 4... 使用 Spring 容器:Spring 容器BeanFactory、ApplicationContext;ApplicationContext 的国际化支持;ApplicationContext 的事件机制;让Bean获取Spring容器;Spring容器中的Bean
7.4 使用 Spring 容器 Spring 有两个核心接口:BeanFactory 和 ApplicationContext,其中ApplicationContext 是 BeanFactory ...
- spring源码深度解析— IOC 之 容器的基本实现
概述 上一篇我们搭建完Spring源码阅读环境,spring源码深度解析—Spring的整体架构和环境搭建 这篇我们开始真正的阅读Spring的源码,分析spring的源码之前我们先来简单回顾下spr ...
- Spring源码-IOC部分-自定义IOC容器及Bean解析注册【4】
实验环境:spring-framework-5.0.2.jdk8.gradle4.3.1 Spring源码-IOC部分-容器简介[1] Spring源码-IOC部分-容器初始化过程[2] Spring ...
- Spring Ioc源码分析系列--Ioc容器BeanFactoryPostProcessor后置处理器分析
Spring Ioc源码分析系列--Ioc容器BeanFactoryPostProcessor后置处理器分析 前言 上一篇文章Spring Ioc源码分析系列--Ioc源码入口分析已经介绍到Ioc容器 ...
- Spring Ioc源码分析系列--Ioc容器注册BeanPostProcessor后置处理器以及事件消息处理
Spring Ioc源码分析系列--Ioc容器注册BeanPostProcessor后置处理器以及事件消息处理 前言 上一篇分析了BeanFactoryPostProcessor的作用,那么这一篇继续 ...
随机推荐
- python登录csdn并自动评论下载资源脚本
功能 1.自动登录csdn 2.查找未评论的资源并自动评论 用到的库 1.python自带的requests,获取以及发送网页数据 2.python自带的time,用作休眠,csdn资源一段时间内只允 ...
- CSS关键字
1.initial initial 关键字用于设置 CSS 属性为它的默认值. initial 关键字可用于任何 HTML 元素上的任何 CSS 属性. 版本: CSS3 JavaScript 语法: ...
- Rstudio设置永久工作路径
Rstudio中 getwd() 获取工作路径 setwd() 设置工作路径 但这种方式设置后每次打开都要重新设置,现在介绍一种设置永久路径的方法
- 处理Oracle中杀不掉的锁
一些ORACLE中的进程被杀掉后,状态被置为"killed",但是锁定的资源很长时间不释放,有时实在没办法,只好重启数据库.现在提供一种方法解决这种问题,那就是在ORACLE中杀不 ...
- Date、String、Calendar、Timestamp类型之间的转化
1.Calendar 转化 String Calendar calendat = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDa ...
- [Oracle] Group By 语句的扩展 - Rollup、Cube和Grouping Sets
常常写SQL语句的人应该知道Group by语句的主要使用方法是进行分类汇总,以下是一种它最常见的使用方法(依据部门.职位分别统计业绩): SELECT a.dname,b.job,SUM(b.sal ...
- delphi label1 文字在窗体上水平来回移动
//文字在窗体上水平来回移动 procedure TForm1.Timer1Timer(Sender: TObject);{ Timer1.Interval:=10;}begin if label1 ...
- java中的正则操作总结
http://www.cnblogs.com/nerxious/archive/2013/01/03/2842910.html 正则表达式在处理字符串的效率上是相当高的 关于正则表达式的使用,更多的是 ...
- material-dialogs
https://github.com/afollestad/material-dialogs
- [MODx] 2. Install some useful packages into ur MODx
1. The package we might need: 2. Install the package: Select Installer Download Extras Install the p ...