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 框架 详解 (二)的更多相关文章

  1. Shiro 安全框架详解二(概念+权限案例实现)

    Shiro 安全框架详解二 总结内容 一.登录认证 二.Shiro 授权 1. 概念 2. 授权流程图 三.基于 ini 的授权认证案例实现 1. 实现原理图 2. 实现代码 2.1 添加 maven ...

  2. Spring Aop 详解二

    这是Spring Aop的第二篇,案例代码很详解,可以查看https://gitee.com/haimama/java-study/tree/master/spring-aop-demo. 阅读前,建 ...

  3. Spring框架详解介绍-基本使用方法

    1.Spring框架-控制反转(IOC) 2.Spring框架-面向切面编程(AOP) 3.Spring 内置的JdbcTemplate(Spring-JDBC) Spring框架-控制反转(IOC) ...

  4. spring框架详解: IOC装配Bean

    1 Spring框架Bean实例化的方式: 提供了三种方式实例化Bean. 构造方法实例化:(默认无参数) 静态工厂实例化: 实例工厂实例化: 无参数构造方法的实例化: <!-- 默认情况下使用 ...

  5. Spring 框架 详解 (三)-----IOC装配Bean

    IOC装配Bean: 1.1.1 Spring框架Bean实例化的方式: 提供了三种方式实例化Bean. * 构造方法实例化:(默认无参数) * 静态工厂实例化: * 实例工厂实例化: 无参数构造方法 ...

  6. Spring 框架 详解 (四)------IOC装配Bean(注解方式)

    Spring的注解装配Bean Spring2.5 引入使用注解去定义Bean @Component  描述Spring框架中Bean Spring的框架中提供了与@Component注解等效的三个注 ...

  7. Spring 框架 详解 (一)

    Spring是分层的JavaSE/EE full-stack(一站式) 轻量级开源框架 * 分层: * SUN提供的EE的三层结构:web层.业务层.数据访问层(持久层,集成层) * Struts2是 ...

  8. spring框架详解

    把之前分享的spring框架整理一份放在这里. 整体架构: Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架 框架图(选自:http://docs.spring.io/spr ...

  9. 【59】Quartz+Spring框架详解

    什么是Quartz Quartz是一个作业调度系统(a job scheduling system),Quartz不但可以集成到其他的软件系统中,而且也可以独立运行的:在本文中"job sc ...

随机推荐

  1. Script to set the Purchase Order Status to ‘OPEN’(将采购订单重新打开)

    Business Requirement: The finance user requests the IT team to change the PO status to OPEN as they ...

  2. 夺命雷公狗---DEDECMS----18dedecms之无可奈何标签-sql标签取出今天更新

    我们在一些开发时候遇到普通标签都解决不了的问题的时候可以尝试下我们dedecms自带的sql标签,几乎可以完成任何的查询需求 语法如下所示: 我们在这里将刚才首页今天更新那块给改写下,原先的是: {d ...

  3. android studio1.0 for Mac环境搭建与demo运行(手动下载gradle,科学上google) 转载

    http://blog.csdn.net/allenffl/article/details/41957907 官网下载 http://developer.android.com/sdk/install ...

  4. [Ubuntu] Ubuntu13.04, the desktop freezed after login

    My os version is Ubuntu13.04, today, after started and logined, my desktop freezed. But i can still ...

  5. jquery 下拉菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. JQuery ajax方法及参数

    ©屋主原创,版权归 todayeeee 所有!如需转载,必须在页面明显位置给出原文链接!商业用途请 联系我!   $.ajax({ type: 'GET',    // 这是请求的方式 可以是GET方 ...

  7. 学习Perl6: slice fastq file

    需求: 只获取 ath 物种的 hairpin 序列 文件格式如下所示,以>打头的为 header,紧跟的为序列[AUCG]+ (Perl5 regexp 格式) #!/usr/bin/env ...

  8. 如何查看Linux操作系统版本

    1. 查看内核版本命令: 360kb.com:~> cat /proc/version Linux version 2.6.32-358.el6.x86_64 (mockbuild@c6b8.b ...

  9. android 之 Crash信息的持久化处理

    需求: 持久化运行时异常的信息 1.CrashHandler.java import android.content.Context; import android.content.pm.Packag ...

  10. android studio自动导包

    http://blog.csdn.net/buaaroid/article/details/44979629 关于导包的设置以上博文解释的很清楚,在此主要强调下这一句: Add unambiguous ...