Spring 框架 详解 (二)
Spring的入门的程序:
1.1.1 下载Spring的开发包:
spring-framework-3.2.0.RELEASE-dist.zip ---Spring开发包
* docs :spring框架api和规范
* libs :spring开发的jar包
* schema :XML的约束文档.
spring-framework-3.0.2.RELEASE-dependencies.zip ---Spring开发中的依赖包
1.1.2 创建web工程引入相应jar包:
spring-beans-3.2.0.RELEASE.jar
spring-context-3.2.0.RELEASE.jar
spring-core-3.2.0.RELEASE.jar
spring-expression-3.2.0.RELEASE.jar
开发的日志记录的包:
com.springsource.org.apache.commons.logging-1.1.1.jar --- 用于整合其他的日志的包(类似Hibernate中slf4j)
com.springsource.org.apache.log4j-1.2.15.jar
1.1.3 创建Spring的配置文件:
在src下创建一个applicationContext.xml
引入XML的约束:
* 找到xsd-config.html.引入beans约束:
<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.xsd">
1.1.4 在配置中配置类:
<bean id="userService" class="cn.itcast.spring3.demo1.HelloServiceImpl"></bean>
1.1.5 创建测试类:
@Test
// Spring开发
public void demo2() {
// 创建一个工厂类.
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"applicationContext.xml");
HelloService helloService = (HelloService) applicationContext.getBean("userService");
helloService.sayHello();
}
1.1.6 IOC和DI(*****)区别?
IOC:控制反转:将对象的创建权,由Spring管理.
DI:依赖注入:在Spring创建对象的过程中,把对象依赖的属性注入到类中.
* 面向对象中对象之间的关系;
* 依赖:
public class A{
private B b;
}
* 继承:is a
* 聚合:
* 聚集:
* 组合:
1.1.7 Spring框架加载配置文件:
ApplicationContext 应用上下文,加载Spring 框架配置文件
加载classpath:
new ClassPathXmlApplicationContext("applicationContext.xml"); :加载classpath下面配置文件.
加载磁盘路径:
new FileSystemXmlApplicationContext("applicationContext.xml"); :加载磁盘下配置文件.
1.1.1 BeanFactory与ApplicationContext区别?
ApplicationContext类继承了BeanFactory.
BeanFactory在使用到这个类的时候,getBean()方法的时候才会加载这个类.
ApplicationContext类加载配置文件的时候,创建所有的类.
ApplicationContext对BeanFactory提供了扩展:
* 国际化处理
* 事件传递
* Bean自动装配
* 各种不同应用层的Context实现
***** 早期开发使用BeanFactory.
Spring 框架 详解 (二)的更多相关文章
- Shiro 安全框架详解二(概念+权限案例实现)
Shiro 安全框架详解二 总结内容 一.登录认证 二.Shiro 授权 1. 概念 2. 授权流程图 三.基于 ini 的授权认证案例实现 1. 实现原理图 2. 实现代码 2.1 添加 maven ...
- Spring Aop 详解二
这是Spring Aop的第二篇,案例代码很详解,可以查看https://gitee.com/haimama/java-study/tree/master/spring-aop-demo. 阅读前,建 ...
- Spring框架详解介绍-基本使用方法
1.Spring框架-控制反转(IOC) 2.Spring框架-面向切面编程(AOP) 3.Spring 内置的JdbcTemplate(Spring-JDBC) Spring框架-控制反转(IOC) ...
- spring框架详解: IOC装配Bean
1 Spring框架Bean实例化的方式: 提供了三种方式实例化Bean. 构造方法实例化:(默认无参数) 静态工厂实例化: 实例工厂实例化: 无参数构造方法的实例化: <!-- 默认情况下使用 ...
- Spring 框架 详解 (三)-----IOC装配Bean
IOC装配Bean: 1.1.1 Spring框架Bean实例化的方式: 提供了三种方式实例化Bean. * 构造方法实例化:(默认无参数) * 静态工厂实例化: * 实例工厂实例化: 无参数构造方法 ...
- Spring 框架 详解 (四)------IOC装配Bean(注解方式)
Spring的注解装配Bean Spring2.5 引入使用注解去定义Bean @Component 描述Spring框架中Bean Spring的框架中提供了与@Component注解等效的三个注 ...
- Spring 框架 详解 (一)
Spring是分层的JavaSE/EE full-stack(一站式) 轻量级开源框架 * 分层: * SUN提供的EE的三层结构:web层.业务层.数据访问层(持久层,集成层) * Struts2是 ...
- spring框架详解
把之前分享的spring框架整理一份放在这里. 整体架构: Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架 框架图(选自:http://docs.spring.io/spr ...
- 【59】Quartz+Spring框架详解
什么是Quartz Quartz是一个作业调度系统(a job scheduling system),Quartz不但可以集成到其他的软件系统中,而且也可以独立运行的:在本文中"job sc ...
随机推荐
- 夺命雷公狗ThinkPHP项目之----企业网站14之文章修改页的完成
这个其实也是挺容易的,我们思路先将栏目页给遍历出来: 这里用了catTree的方法,因为我们要对遍历出来的数据进行排序的,然后来到前端进行完成列表: <!doctype html> < ...
- At_speed_test
Logic BIST通过将很多的tester functionality放在CUT中,减少了test costs,但是更重要的一方面是at-speed testing. At-speed test包括 ...
- Sql server analysis service 通过IIS连接时的最大连接数问题
做过SSAS项目的大部分人都应该知道SSAS是可以通过在IIS上建立代理站点的方式来建立远程连接的,这样可以绕过连接到SSAS时需要在同一个域环境下通过域用户来验证的问题,这样即使连接到SSAS的客户 ...
- selenium webdriver三种等待方法
webdriver三种等待方法 1.使用WebDriverWait from selenium import webdriverfrom selenium.webdriver.common.by im ...
- linux设备驱动归纳总结(一)内核的相关基础概念【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-59413.html linux设备驱动归纳总结(一):内核的相关基础概念 xxxxxxxxxxxxxx ...
- Android BlueDroid(一):BlueDroid概述 【转】
转自:http://blog.csdn.net/xubin341719/article/details/40378205 版权声明:本文为博主原创文章,未经博主允许不得转载. 关键词:bluedroi ...
- linux下共享内存mmap和DMA(直接访问内存)的使用 【转】
转自:http://blog.chinaunix.net/uid-7374279-id-4413316.html 介绍Linux内存管理和内存映射的奥秘.同时讲述设备驱动程序是如何使用“直接内存访问” ...
- POJ 1260:Pearls(DP)
http://poj.org/problem?id=1260 Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8 ...
- android5.x以上 状态栏透明的问题
1.先在style中把 statusBarColor 设置为透明 如下 <item name="android:statusBarColor">@android:co ...
- [HTML]网页开发学习笔记
为了要开发一套教学使用的教师管理系统,(客户需求使用网页做教师控制端口)我便学习了一下HTML网页开发. 很不错的学习开发的网站:http://www.w3school.com.cn/index.ht ...