Spring3.0官网文档学习笔记(四)--3.1~3.2.3
3.1 Spring IoC容器与Beans简单介绍
BeanFactory接口提供对随意对象的配置;
ApplicationContext是BeanFactory的子接口。整合了Spring Aop功能,消息资源控制。事件公布,应用层特殊的上下文(在web应用中)
由IoC容器实例化、组装、管理的对象都是Bean
3.2 容器概述
org.springframework.context.ApplicationContext代表Spring IoC容器,而且负责通过读取配置元数据来实例化、配置、组装Bean。配置元数据能够通过三种形式表示:xml,Java凝视,Java code(这个不懂)
在独立的环境中。实例化ClassPathXmlApplicationContext或FileSystemXmlApplicationContext对象。
3.2.1 配置元数据
除了配置在xml文件里,还有两种方法:
Annotation-based configuration: ?
Java-based configuration: ?
你能够使用Spring's integration with AspectJ配置不在IoC容器控制下的对象?
基于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-3.0.xsd"> <bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean> <bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean> <!-- more bean definitions go here --> </beans>
3.2.2 实例化一个容器
ApplicationContext context =
new ClassPathXmlApplicationContext(new String[] {"services.xml", "daos.xml"});
Note:第4章有更方便的机制读取XML文件?
3.2.2.1 基于XML配置的元数据的组成
<beans>
<import resource="services.xml"/>
<import resource="resources/messageSource.xml"/>
<import resource="/resources/themeSource.xml"/>
<bean id="bean1" class="..."/>
<bean id="bean2" class="..."/>
</beans>
services.xml必须位于包括该文件的xml文件同个文件夹或者是在classPath文件夹下。
能够通过相对路径“../path”这样的方式来配置文件路径,可是这方法并不推荐(用这样的方式创建出来的是依赖文件是在当前应用的外部?)。尤其不推荐用于"classpath:"这样的URL中(执行时解决程序会选择“近期的”classpth,并查看它的父文件夹,导致找不到相应的xml文件)。
能够使用:"file:C:/config/services.xml"或"classpath:/config/services.xml"。可是要记住假设使用绝对路径的话,就存在耦合问题了。
3.2.3 使用容器
// create and configure beans
ApplicationContext context =
new ClassPathXmlApplicationContext(new String[] {"services.xml", "daos.xml"}); // retrieve configured instance
PetStoreServiceImpl service = context.getBean("petStore", PetStoreServiceImpl.class); // use configured instance
List userList service.getUsernameList();
Spring3.0官网文档学习笔记(四)--3.1~3.2.3的更多相关文章
- Spring3.0官网文档学习笔记(一)
Part 1 Spring框架概述 Spring是模块化的,在应用中仅仅须要引入你所须要用到的模块的jar包,其余的jar包不用引入. spring框架支持声明式的事务管理,通过RMI或web ser ...
- Spring3.0官网文档学习笔记(七)--3.4.2
3.4.2 依赖与配置的细节 3.4.2.1 Straight values (primitives, Strings, and so on) JavaBeans PropertyE ...
- Spring3.0官网文档学习笔记(二)
1.3 使用场景 典型的成熟的spring web应用 spring使用第三方框架作为中间层 远程使用场景 EJB包装 1.3.1 依赖管理.命名规则(包) spring-*.jar *号代表 ...
- Spring3.0官网文档学习笔记(八)--3.4.3~3.4.6
3.4.3 使用depends-on 使用depends-on能够强制使一个或多个beans先初始化,之后再对这个bean进行初始化. 多个bean之间用","." ...
- android官网文档学习笔记
1.android的四大组件的了大概功能 activity:负责显示界面,和用户交互. service:运行在后台. content provider:为程序app之间的数据访问提供接口. broad ...
- Spring Security 官网文档学习
文章目录 通过`maven`向普通的`WEB`项目中引入`spring security` 配置 `spring security` `configure(HttpSecurity)` 方法 自定义U ...
- mongodb官网文档阅读笔记:与写性能相关的几个因素
Indexes 和全部db一样,索引肯定都会引起写性能的下降,mongodb也没啥特别的,相对索引对读性能的提示,这些消耗通常是能够接受的,所以该加入的索引还是要加入.当然须要慎重一些.扯点远的,以前 ...
- (五)Spring Boot官网文档学习
文章目录 SpringApplication SpringApplication 事件 `ApplicationContext ` 类型 访问传递给 `SpringApplication` 的参数 A ...
- (二)Spring Boot 官网文档学习之入门
文章目录 Spring Boot 是什么 系统要求 Servlet 容器 Maven方式安装Spring Boot 编写第一个 Spring Boot 项目 原文:https://docs.sprin ...
随机推荐
- webpack2 热加载js 文件
如果只要普通的热加载 只要如下配置就好了 package.json { "devDependencies": { "webpack": "^2.6.1 ...
- [BalkanOI2016]Lefkaritika
题目大意: 一个n*m的格子上有b个障碍物,现在让你往上面放正方形(长宽在格线上).问可以放多少种边长.位置不同的正方形? 思路: 很容易想到一个O(n^3)的暴力: 首先前缀和,然后枚举某一个顶点和 ...
- Generator函数(一)
Generator函数是ES6提供的一种异步编程解决方案,语法行为与传统函数完全不同.对于这个函数有多种理解.从语法上来理解,可以将它理解成一个状态机,封装了多个内部状态.内部的不同状态是通过yiel ...
- codevs 1349 板猪的火车票
1349 板猪的火车票 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 奸商zn(请勿对号入座)开办了一家火车公司,弱弱的板猪 ...
- ERROR 1044: Access denied for user: 'songyan' to database 'yikexiao' 的错误。
问题描述:新买的服务器,刚安装了mysql,创建了一个用户,也忘记了给他分配了什么权限,今天在建库的时候出现了这个问题. 出错原因:度娘告诉我是因为songyan用户没有建库的权限报的错. 解决: ( ...
- OpenVPN官方资源下载和官方教程入口
官方资源: https://openvpn.net/index.php/open-source/downloads.html 2.4.4版本下载:(链接: https://pan.baidu.com/ ...
- Word中公式从单栏排版变为双栏排版后公式和编号错开了
如上图公式(2),把自己做的共识从通栏复制到期刊的双栏里就变成这样了(先复制过来参考文献,再复制正文,那么参考文献没事),原来一直搞不懂,今天把它显示所有标记发现多了个制表符(我原来以为是行标记),鼠 ...
- 基于tiny4412的Linux内核移植 -- eMMC驱动移植(六)
作者信息 作者: 彭东林 邮箱:pengdonglin137@163.com QQ:405728433 平台简介 开发板:tiny4412ADK + S700 + 4GB Flash 要移植的内核版本 ...
- 【JSP EL】使用EL表达式比较 动态选中 select中的option
<option value="${k.key }" ${KPIThis.parent.parent.thisId == k.key ? "selected" ...
- pycharm的插件pylint报错:java.lang.Throwable: Write-unsafe context! Model changes are allowed from write-safe contexts only. Please ensure you're using invokeLater/invokeAndWait with a correct modality stat
java.lang.Throwable: Write-unsafe context! Model changes are allowed from write-safe contexts only. ...