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

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. Learning ROS for Robotics Programming Second Edition学习笔记(三) indigo rplidar rviz slam

    中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS for Robotics Pr ...

  2. OpenCV GUI基本操作,回调函数,进度条,裁剪图像等

    代码为转载,出处找不到了,不贴了 工具条进度条: // ConvertColor.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #incl ...

  3. Developing User Interfaces

      Developing a User Interface with ADF Faces Purpose This tutorial covers developing the user interf ...

  4. SpriteBuilder中的CCB Node尺寸

    当你创建一个类型为Layer的CCB文件时,你将注意到它的默认尺寸大小为568x384. 568个点是4英寸iphone的宽度,同时iPad屏幕只有512个点宽,更准确的说--SpriteBuilde ...

  5. MySQL 5.6初始配置调优

    原文链接: What to tune in MySQL 5.6 after installation原文日期: 2013年09月17日翻译日期: 2014年06月01日翻译人员: 铁锚 随着 大量默认 ...

  6. 记——加快gradle 构建速度的经验

    Gradle作为一个新的构建系统,无疑在灵活,扩展,跨平台等各方面都表现得非常优秀,然而,它也有一点备受吐槽,就是速度慢.以下为本人使用gradle过程中,几次加快gradle构建速度的经验之谈. 本 ...

  7. rails常用命令备忘

    rails new xxx 创建一个新rails项目 rails generate scaffold xxx 创建表模型,视图,控制器和迁移的"脚手架" rake db:migra ...

  8. ubuntu18.04 安装mysql 5.7.22

    后台下载,脱离终端控制 后台下载,可以节省ssh资源占用,且不会因为ssh连接断开而导致下载失败,适用于操作远端云服务器 wget -b 启动后台下载 -o 指定logfile(记录下载进度信息) w ...

  9. AngularJS中service,factory,provider的区别

    一.service引导 刚开始学习Angular的时候,经常被误解和被初学者问到的组件是 service(), factory(), 和 provide()这几个方法之间的差别.This is whe ...

  10. 自制无线共享工具C++源代码

    // wire.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <string.h> using namespace ...