spring

第一章

Spring模块规划图

核心架包

spring-beans-4.0.0.RELEASE、
spring-core-4.0.0.RELEASE、
spring-context-4.0.0.RELEASE、
spring-expression-4.0.0.RELEASE

AOP+Aspects(面向切面编程模块)

spring-aop-4.0.0.RELEASE、spring-aop-4.0.0.RELEASE

数据访问/:Spring数据库访问模块

spring-jdbc-4.0.0.RELEASE、spring-orm(Object Relation Mapping)-4.0.0.RELEASE、
spring-ox(xml)m-4.0.0.RELEASE、spring-jms-4.0.0.RELEASE、(Intergration)
spring-tx-4.0.0.RELEASE(事务)

Web:Spring开发web应用的模块;

spring-websocket(新的技术)-4.0.0.RELEASE、
spring-web-4.0.0.RELEASE、和原生的web相关(servlet)
spring-webmvc-4.0.0.RELEASE、开发web项目的(web)
spring-webmvc-portlet-4.0.0.RELEASE(开发web应用的组件集成)

ecplise插件的安装

1.ecplise查看版本号: Help->About Eclipse-->点击自己eclipse的图标

2.选中带有SpringIDE的四项

3.去掉hide与contact选框

第二章

核心思想

IOC:控制反转

​ 控制:资源的获取方式。

​ 从主动自己创建。如:BookService bs = new BookService();

​ 到被动:直接从容器获取,容器进行对象的管理

​ 容器:(婚介所)管理所有的组件(有功能的类);容器:主动的new资源变为被动的接受资源 ;

DI:依赖注入

​ 容器通过反射的形式,将容器中对象注入(利用反射给属性赋值);

框架编写流程

1.导包:

核心容器
spring-beans-4.0.0.RELEASE.jar
spring-context-4.0.0.RELEASE.jar
spring-core-4.0.0.RELEASE.jar
spring-expression-4.0.0.RELEASE.jar
commons-logging-1.1.3.jar
Spring运行的时候依赖一个日志包;没有就报错;

2.写配置

spring的配置文件中,集合了spring的ioc容器管理的所有组件(会员清单);创建一个Spring Bean Configuration File(Spring的bean配置文件);

<!--
一个Bean标签可以注册一个组件(对象、类) (会员对象)
class:写要注册的组件的全类名(会员真实名字)
id:这个对象的唯一标示;(会员号)
--> <bean id="person01" class="com.atguigu.bean.Person">
<!--使用property标签为Person对象的属性赋值
name="lastName":指定属性名
value="张三":为这个属性赋值
-->
<property name="lastName" value="张三"></property>
<property name="age" value="18"></property>
<property name="email" value="zhangsan@atguigu.com"></property>
<property name="gender" value="男"></property>
</bean>

3.测试

package com.atguigu.test;

import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.atguigu.bean.Person; public class IOCTest { @Test
public void test() {
//ApplicationContext 代表ioc容器
//ClassPathXmlApplicationContext:当前应用的xml配置文件在 ClassPath下
//跟spring的配置文件得到ioc容器对象
ApplicationContext ioc = new ClassPathXmlApplicationContext("ioc.xml"); //容器帮我们创建了对象了
Person bean = (Person) ioc.getBean("person01"); System.out.println(bean);
} } 打印结果: Person [lastName=张三, age=18, gender=男, email=zhangsan@guigu]

说明:

 1)、src,源码包开始的路径,称为类路径的开始;(source folder 等价与src)
*所有源码包里面的东西都会被合并放在类路径里面;
*java:/bin/
*web:/WEB-INF/classes/
2)、导包commons-logging-1.1.3.jar(依赖)
3)、先导包再创建配置文件;
4)、Spring的容器接管了标志了s的类(装了插件才有特效)

细节:

new ClassPathXMlApplicationContext("ioc.xml");ioc容器的配置文件在类路径下;
FileSystemXmlApplicationContext("F://ioc.xml");ioc容器的配置文件在磁盘路径下; 1)ApplicationContext(IOC容器的接口)
2)给容器中注册一个组件;我们也从容器中按照id拿到了这个组件的对象?
组件的创建工作,是容器完成;
Person对象是什么时候创建好了呢?
容器中对象的创建在容器创建完成的时候就已经创建好了;
3)同一个组件(对象)在ioc容器中是单实例的、
4)、容器中如果没有这个组件,获取组件?报异常
* org.springframework.beans.factory.NoSuchBeanDefinitionException:
* No bean named 'person03' is defined
* 5)、ioc容器在创建这个组件对象的时候,(property)会利用setter方法为javaBean的属性进行赋值;
* 6)、javaBean的属性名是由什么决定的?getter/setter方法是属性名;set去掉后面那一串首字母小写就是属性名;
* private String lastName;?
* 所有getter/setter都自动生成!

Spring笔记01的更多相关文章

  1. Spring笔记01(基础知识)

    1.基础知识 01.Spring:轻量级Java EE开源框架,它是由Rod Johnson为了解决企业应用程序开发的复杂性而创建. 02.目标:实现一个全方位的整合框架,实现“一站式”的企业应用开发 ...

  2. Spring笔记 #01# 一个小而生动的IOC例子代码

    索引 Spring容器的最小可用依赖 用XML定义元数据 实例化容器&使用容器 例子中仅包含两种类:英雄类Hero和武器类Weapon. 演示DI:给Hero初始化Weapon 演示AOP:法 ...

  3. Spring笔记01_下载_概述_监听器

    目录 Spring笔记01 1.Spring介绍 1.1 Spring概述 1.2 Spring好处 1.3 Spring结构体系 1.4 在项目中的架构 1.5 程序的耦合和解耦 2. Spring ...

  4. SaToken学习笔记-01

    SaToken学习笔记-01 SaToken版本为1.18 如果有排版方面的错误,请查看:传送门 springboot集成 根据官网步骤maven导入依赖 <dependency> < ...

  5. Redis 笔记 01:入门篇

    Redis 笔记 01:入门篇 ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ...

  6. 软件测试之loadrunner学习笔记-01事务

    loadrunner学习笔记-01事务<转载至网络> 事务又称为Transaction,事务是一个点为了衡量某个action的性能,需要在开始和结束位置插入一个范围,定义这样一个事务. 作 ...

  7. 《30天自制操作系统》笔记(01)——hello bitzhuwei’s OS!

    <30天自制操作系统>笔记(01)——hello bitzhuwei's OS! 最初的OS代码 ; hello-os ; TAB=4 ORG 0x7c00 ; 指明程序的装载地址 ; 以 ...

  8. 《The Linux Command Line》 读书笔记01 基本命令介绍

    <The Linux Command Line> 读书笔记01 基本命令介绍 1. What is the Shell? The Shell is a program that takes ...

  9. PHP 学习笔记 01

    例子: 为什么要学PHP 主观原因: 前段时间在学校处理了毕业的一些事情,回到上海后开始了找工作的旅程.意向工作是WPF开发或者ASP.NET 作为后端的WEB开发. 陆陆续续一直在面试,其中有一家公 ...

随机推荐

  1. Vuex基本使用的总结--转载

    在 Vue 的单页面应用中使用,需要使用Vue.use(Vuex)调用插件.使用非常简单,只需要将其注入到Vue根实例中. import Vuex from 'vuex' Vue.use(Vuex) ...

  2. iOS中的NSOperation线程

    1.除NSThread之外的第二种多线程的编程方法   2.采用NSOperation(线程操作,通常用他的子类)和NSOperationQueue(线程队列)搭配来做多线程开发,采用NSOperat ...

  3. JavaScript—图片与base64编码互相转换

    图片转换为base64编码 <input type = "file" id = "file" onchange="popFileName(thi ...

  4. Shell命令-网络操作之基础之ping、route

    文件及内容处理 - ping.route 1. ping:测试主机之间网络的连通性 ping命令的功能说明 ping 命令用于检测主机.执行 ping 指令会使用 ICMP 传输协议,发出要求回应的信 ...

  5. windows防火墙失效

    在某些情况下,我们希望阻止某款软件联网,比如防止软件更新. 通常来说使用windows自带的防火墙是可以阻止软件联网的,但在我的电脑上它却失效了,无法起到阻止软件联网的作用. 我的操作系统: OS 名 ...

  6. python,adb,分别给多个设备安装多个apk文件,os.popen(); os.system; os.path.splitext(); a.split(' \t'); readlines(); append(); os.path.join(); time.sleep();

    #encoding:utf-8import os,time#=======================查找手机设备序列号=============a='adb devices'b=os.popen ...

  7. template might not exist or might not be accessible by any of the configured Template Resolvers at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869)

    org.thymeleaf.exceptions.TemplateInputException: Error resolving template [code/leading], template m ...

  8. 2、zabbix3.4的安装

    系统版本:centos7 数据库版本:mysql二进制安装5.7 zabbix:阿里云安装3.4 一.Zabbix的安装 Zabbix3.4版本官方安装手册链接:https://www.zabbix. ...

  9. 让人又爱又恨的this

    this是个神奇的东西, 既可以帮助我们把模拟的类实例化. 又可以在事件绑定里准确指向触发元素. 还可以帮助我们在对象方法中操作对象的其他属性或方法. 甚至可以在使用apply.call.bing.f ...

  10. NOIP 2011 提高组初赛错题简析

    Preface 好久没做初赛题了,据说今年的审核会更加严苛,作为一名去年未PY时只有\(92\)分的蒟蒻,我今年看来是\(90\)分都莫得了 然而今年也没怎么看重初赛,结果现在才来做,翻车到了\(84 ...