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 ...
随机推荐
- Redux 和 Redux thunk 理解
1: state 就像 model { todos: [{ text: 'Eat food', completed: true }, { text: 'Exercise', completed: fa ...
- <四边形不等式优化>[NOI1995]石子合并
留个坑 挺套路的 明天来写个总结 #include<cstdio> #include<algorithm> inline int read() { int x = 0,f = ...
- 【枚举】bzoj1072 [SCOI2007]排列perm
暴力,next_permutation函数用于枚举出下一个排列.sscanf函数用于将字符串转化成数字. #include<cstdio> #include<cstring> ...
- Manthan, Codefest 16 E. Startup Funding ST表 二分 数学
E. Startup Funding 题目连接: http://codeforces.com/contest/633/problem/E Description An e-commerce start ...
- Ubuntu 16.04下没有/var/log/messages文件问题解决
1.问题描述 今天需要查看Ubuntu系统的日志文件,但却没有找到/var/log/messages这个文件.网上搜素资料,说是要配置/etc/syslog.conf.syslog采用可配置的.统一的 ...
- 简单理解SNAT回流中的概念:路由器怎么知道外网返回的数据是局域网中哪台主机的
内网到外网用的是NAT技术(地址封装)外网到内网用的是端口映射(PNAT)计算机的端口又65535(0-65534),你说的那些有名气的端口大多都是0-1023之间的你说的这个问题很简单,但首先你要懂 ...
- CentOS通过日志反查入侵(转)
1.查看日志文件 Linux查看/var/log/wtmp文件查看可疑IP登陆 last -f /var/log/wtmp 该日志文件永久记录每个用户登录.注销及系统的启动.停机的事件.因此随着系统 ...
- winform WebBrowser如何修改使用默认的IE浏览器版本
在搜了一些相关资料原来WebBrowser使用的是IE的兼容模式进行浏览(IE7模式). 建议:先添加注册表中,然后使用注册表编辑器导出功能,产生reg注册文件:方便日后使用. Winform We ...
- [转]SSIS包的调用方式
本文转自:http://www.cnblogs.com/lijun4017/archive/2008/12/04/1347701.html 编写简单SSIS包光看MSDN应该就问题不大了,最近几天几个 ...
- Android studio 和 Eclipse快捷键对比
操作 studio eclipse debug/run 计算变量值 alt+F8 ctrl+shift+I 跳到下一步 F8 F6 跳到下一个断点 shift+F8 F8 进入到代码 F7 F5 ...