------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------

Spring

提起Spring,就会想到企业级框架这个词

  企业级系统:

    1.大规模:用户数量多,数据规模庞大,数据众多

    2.性能和安全性要求更高

    3.业务复杂

    4.灵活应变

--------------------------------------------------------------------------------------------------------------------------------------------------

我觉得先了解一下Spring的地位和他的作者比较好

  Spring:java中的核心框架,没有它就没有现在的java的地位,如果Spring挂掉了,3-5年内java必挂

  Spring 的作者:Rod Johnson

    

    他是SpringFramework创始人,interface21 CEO

    丰富的C/C++背景,丰富的金融行业背景

    1996年开始关注java服务器端技术

    2002年著写《Expoert one-on-oneJ2EE设计与开发》,改变了Java世界

    技术主张以实用为本,音乐学博士

--------------------------------------------------------------------------------------------------------------------------------------------------

  接下来讲讲Spring的内容,放俩张图片

    

    Data/Access:数据访问

    Web:网络

    AOP:面向切面编程

    Instrumentatio:插桩

    Core Container:核心(下面的一张图有他的核心的内容,先理解这张

    Test:测试,单测

    

    官网:Spring.io        拿的图

--------------------------------------------------------------------------------------------------------------------------------------------------

  Spring的核心IOC和AOP(本处详解IOC)

    IOC:控制反转:(Inverse Of Control)
      控制反转(Inversion of Control),是一个重要的面向对象编程的法则来削减计算机程序的耦合问题,也是轻量级的Spring框架的核心,beans。
      理解一:将组件对象(业务对象)的控制权从代码本身转移到外部容器()
      理解二:IOC控制反转:说的是创建对象实例的控制权从代码控制剥离到IOC容器(spring容器)控制,实际就是你在xml文件控制,侧重于原理。

    AOP:面向切面编程;  (Aspect Oritend Programming)

    提及一下对象间的关系把

    

--------------------------------------------------------------------------------------------------------------------------------------------------

第一个案例:

    1.下载jar包:(我提供节点)

        <!--单元测试的依赖  ctrl+shif+/-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency> <!--Spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.2..RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2..RELEASE</version>
</dependency> <!--aop使用的jar-->
<dependency>
<groupId> org.aspectj</groupId >
<artifactId> aspectjweaver</artifactId >
<version> 1.8.</version>
</dependency>

    2.一个普通类

package cn.dawn.day01.service;

/**
* Created by Dawn on 2018/3/3.
*/
public class DawnService { private String workInfo;
private Integer age;
public void work(){
System.out.println("info"+workInfo);
} @Override
public String toString() {
return "DawnService{" +
"workInfo='" + workInfo + '\'' +
", age=" + age +
'}';
} public String getWorkInfo() {
return workInfo;
} public void setWorkInfo(String workInfo) {
this.workInfo = workInfo;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
}
}

    3.大配置文件

<?xml version="1.0" encoding="UTF-8"?>
<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"> <bean id="service" class="cn.dawn.day01.service.DawnService">
<property name="workInfo" value="第一个Spring程序"></property>
<property name="age" value=""></property>
</bean>
</beans>

    4.单测

package cn.dawn.day01;

import cn.dawn.day01.service.DawnService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* Created by Dawn on 2018/3/3.
*/
public class test20180303 {
@Test
/*入门案例*/
public void t01(){
ApplicationContext context=new ClassPathXmlApplicationContext("ApplicationContext01.xml");
DawnService service = (DawnService) context.getBean("service");
System.out.println(service);
}
}

    在没有new 的情况下,就拿到了他的实现

    ApplicationContext context=new ClassPathXmlApplicationContext("ApplicationContext01.xml");

    这行如果不理解我就放一张图

    

    看到ClassPathXmlApplicationContext前面的C吗?在结合这个,表示他是ApplicationContext的实现类,里氏替换,为什么不可以用

--------------------------------------------------------------------------------------------------------------------------------------------------

    还记得我提了的IOC吗?我不是说他把创建对象的控制权交给了Spring容器嘛,那么容器在什么时候创建对象呢,是getBean的时候吗?还是。。。。(小实验)

    在刚才的那个普通类中,添加一个构造,如下

public DawnService(){
System.out.println("========================DawnService创建=======================");
}

    单测方法如下

    @Test
/*入门案例*/
public void t01(){
ApplicationContext context=new ClassPathXmlApplicationContext("ApplicationContext01.xml");
/*DawnService service = (DawnService) context.getBean("service");
System.out.println(service);*/
}

    运行结果:

    

    结论就是Spring容器初始化的时候就把bean中的对象实例化了

SSM-Spring-01:Spring的概念+入门案例的更多相关文章

  1. Spring 01: Spring配置 + IOC控制反转 + Setter注入

    简介 Spring框架是一个容器,是整合其他框架的框架 他的核心是IOC(控制反转)和AOP(面向切面编程),由20多个模块构成,在很多领域都提供了优秀的问题解决方案 特点 轻量级:由20多个模块构成 ...

  2. Spring学习笔记(一)—— Spring介绍及入门案例

    一.Spring概述 1.1 Spring是什么 Spring是一个开源框架,是于2003年兴起的一个轻量级的Java开发框架, 由Rod Johnson 在其著作<Expert one on ...

  3. 回顾Spring MVC_01_概述_入门案例

    SpringMVC: SpringMVC是Spring为展现层提供的基于MVC设计的优秀的Web框架,是目前最主流的MVC框架之一 SpringMVC通过注解,让POJO成为处理请求的控制器,而无须实 ...

  4. SSM(spring mvc+spring+mybatis)学习路径——1-1、spring入门篇

    目录 1-1 Spring入门篇 专题一.IOC 接口及面向接口编程 什么是IOC Spring的Bean配置 Bean的初始化 Spring的常用注入方式 专题二.Bean Bean配置项 Bean ...

  5. Spring(二)--Spring入门案例

    Spring入门案例 1.需要的实体类 2.需要的接口和实现类 3.需要的service和实现类 /** * service层的作用 * 在不改变dao层代码的前提下,增加业务逻辑操作 */ publ ...

  6. spring-cloud-Zuul学习(一)【基础篇】--入门案例【重新定义spring cloud实践】

                                                                                                    -- 2 ...

  7. spring原理案例-基本项目搭建 01 spring framework 下载 官网下载spring jar包

    下载spring http://spring.io/ 最重要是在特征下面的这段话,需要注意: All avaible features and modules are described in the ...

  8. spring入门--spring入门案例

    spring是一个框架,这个框架可以干很多很多的事情.感觉特别吊.但是,对于初学者来说,很难理解spring到底是干什么的.我刚开始的时候也不懂,后来就跟着敲,在后来虽然懂了,但是依然说不明白它到底是 ...

  9. 1.Spring框架入门案例

    一.简单入门案例 入门案例:IoC 1.项目创建与结构 2.接口与实现类 User.java接口 package com.jd.ioc; /** * @author weihu * @date 201 ...

随机推荐

  1. Java-ServletRequestEvent-ServletRequestAttributeEvent

    /** * Events of this kind indicate lifecycle * events for a ServletRequest. * The source of the even ...

  2. Linux - test测试标志的意思总结

    测试的标志 代表意义 1. 关於某个档名的『文件类型』判断,如 test -e filename 表示存在否 -e 该『档名』是否存在?(常用) -f 该『档名』是否存在且为文件(file)?(常用) ...

  3. Linux完整备份工具 - dump, restore(现在基本不用这两个)

    dump 其实 dump 的功能颇强,他除了可以备份整个文件系统之外,还可以制定等级喔!什么意思啊! 假设你的 /home 是独立的一个文件系统,那你第一次进行过 dump 后,再进行第二次 dump ...

  4. PS 滤镜算法原理——染色玻璃

    %%%% 完成PS 中的染色玻璃滤镜特效 clc; clear all; close all; Image=imread('4.jpg'); Image=double(Image); Gray_Ima ...

  5. redis持久化AOF与RDB

    RDB 持久化可以在指定的时间间隔内生成数据集的时间点快照(point-in-time snapshot). AOF 持久化记录服务器执行的所有写操作命令,并在服务器启动时,通过重新执行这些命令来还原 ...

  6. IoC和DI的基本概念的思维导图

    最近在学习Spring开发,IoC这个概念让我有点儿迷糊,控制反转这四个字是在是无法做到望文生义,于是乎就找了一些材料来学习,研究了半天,绘制了下面这幅思维导图.仅供参考!

  7. Django之admin的使用和源码剖析

    admin组件使用 Django 提供了基于 web 的管理工具. Django 自动管理工具是 django.contrib 的一部分.你可以在项目的 settings.py 中的 INSTALLE ...

  8. pywinauto处理UI自动化

    之前一个项目的特殊性, 以及一些操作权限上的问题,不能使用现有工具进行UI自动化. 在一些资深tester建议下决定采用Python的pywinauto模块来处理Windows控件的UI操作. 1. ...

  9. 单链表反转(Singly Linked Lists in Java)

    单链表反转(Singly Linked Lists in Java) 博客分类: 数据结构及算法   package dsa.linkedlist; public class Node<E> ...

  10. css 字体两端对齐

    我想作为一个前端工作者,总会遇到这样的场景,一个表单展示的字段标题有4个字也有2个字的时候,这样子同时存在想展示的美观一点,就需要字体两端对齐了,其实实现方式很简单,我针对其中一种来做下介绍,以后方法 ...