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. 8. 星际争霸之php设计模式--享元模式

    题记==============================================================================本php设计模式专辑来源于博客(jymo ...

  2. Ubuntu + CentOS7 搭建tftp Server

    基于Ubuntu系统做的tftp服务器,基于CentOS 7都差不多,书写了关键命令,测试过Ubuntu 12.0.4 和CentOS 7环境 1.介绍tftp服务器     TFTP(Trivial ...

  3. HorizontalScrollView的配置

    package com.exmple.jinritoutiao; import java.util.ArrayList;import java.util.Calendar;import java.ut ...

  4. 空格和TAB键混用错误:IndentationError: unindent does not match any outer indentation level

    转自:http://www.crifan.com/python_syntax_error_indentationerror/comment-page-1/ [已解决]Python脚本运行出现语法错误: ...

  5. android 中activity调用本地service中的方法。

    1.自定义一个接口,暴露服务中的方法 public interface IService {    /**服务中对外暴露的方法 */    void methodInService();} 2.自定一 ...

  6. init_MUTEX 与 sema_init 函数【转】

    转自:http://blog.chinaunix.net/uid-7332782-id-3211627.html 在编译Linux设备驱动程序学习(1)-字符设备驱动程序中scull.c程序时,报错: ...

  7. 微信清理H5真的太早了?这会是应用号发布的前兆吗

    三少爷的剑  2016-04-18 21:05 收藏35 评论7   两天之内,整个 H5 游戏创业陷入了两年狂热期以来最冷的冰点. 每一个正在忙于 H5 小游戏开发的开发者都在忙于砍掉游戏代码中有关 ...

  8. 6、XML(2)

    1 总结XML基础 XML基础 1)XML的作用 1.1 作为软件配置文件 1.2 作为小型的"数据库" 2)XML语法(由w3c组织规定的) 标签: 标签名不能以数字开头,中间不 ...

  9. Python包管理工具介绍

    常见的包管理工具及关系 setuptools -->distribute easy_install-->pip 1.distribute distribute是对标准库disutils模块 ...

  10. 基本包装类型:Boolean、Number 和String

    /* var box = 'Mr. Lee'; //基本类型 //alert(box); //alert(typeof box); alert(box.substring(2)); //对象.方法(参 ...