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. 1.java容器基本内容

    目录 java容器概述 1.collection接口 (1)collection接口方法 (2)set接口实现类 (3)list接口实现类 (4)queue接口实现类 2.map接口 java容器概述 ...

  2. 从0系统学Android-2.1Activity的使用

    更多精品文章分类 第二章:先从看的到的入手-Activity 上一章成功创建了自己的第一个项目.这一章从页面入手,来进行学习. 2.1 Activity 是什么 Activity 是一种可以包含用户界 ...

  3. 如何开发优质的 Flutter App:Flutter App 软件测试指南

    继上一场GitChat文章发布之后,博主又为朋友们带来另一场Chat.这一次我们主要聊一聊Flutter App的测试环节. 众所周知,应用的功能越多,手动测试的难度就越大.一套完整的自动化测试将帮助 ...

  4. python生产者和消费者模式实现(三)进程池方式

    注意:如果要使用Pool(进程池方式)创建进程,就需要使用multiprocessing.Manager()中的 Queue(),而不是multiprocessing.Queue() import t ...

  5. mysql connector c++ 1.1 API初步体验

    mysql connector c++ 1.1 API初步体验 1,常用的头文件 #include <mysql_connection.h> #include <mysql_driv ...

  6. spark-shell 中rdd常用方法

    centos 7.2     spark 2.3.3      scala 2.11.11    java 1.8.0_202-ea spark-shell中为scala语法格式 1.distinct ...

  7. luoguP1447 [NOI2010]能量采集

    https://www.luogu.org/record/22874213 题目大意:给定n和m,求Σ(1<=i<=n)Σ(1<=j<=m)GCD(i,j)* 2-1 i和j的 ...

  8. HAproxy四层TCP负载均衡配置及测试

    --------------------------------------------------centos 7 处理--------------------------------------- ...

  9. pyplot中的一些函数

    from matplotlib import pyplot as plt plt.ylabel(‘Grade’) : y轴的名称 plt.xlabel(‘Grade’) : x轴的名称 plt.tit ...

  10. Ubuntu环境下打开Firefox报错: Firefox is already running, but is not responding.

    在ubuntu下启动firefox可能会报错 Firefox is already running, but is not responding. To open a new window, you ...