zoukankan      html  css  js  c++  java
  • 初识SpringBoot

    SpringMVC构建项目

      在日常开发中,我们通常会选择SpringMVC + Maven的方式去构建一个web项目,需要配置各种xml文件非常耗时,大概的构建步骤如下:

    1. 创建一个基于maven工程的项目架构
    2. 添加spring的依赖,springmvc以及servlet api依赖
    3. 配置web.xml以及dispatcher-servlet.xml
    4. 创建Controller,发送http请求
    5. 把工程发布到servler容器,通常用tomcat

    具体的流程可以查考如下链接:https://www.cnblogs.com/xiaoxiaoyu0707/p/9897481.html。

      其实在实际开发过程中,我们只想关注第四步中具体的业务设计,并不想关心架构的配置,但现实往往会在这些配置上花费很长时间,由此springboot应运而生。

    SpringBoot的产生

      2012年10月份,一个叫Mike Youngstrom(扬斯特罗姆)在Spring Jira中创建了一个功能请求,要求在Spring Framework中支持无容器Web应用程序体系结构,他谈
    到了在主容器引导 spring 容器内配置 Web 容器服务。

    到底什么是SpringBoot

      到底什么是springboot呢?我觉得springboot并不是一门新的技术,它产生自spring,是在spring Framework基础上应运而生的,遵循默认大于配置的原则,那么何为

    默认大于配置?其实就是在你构建一个springboot工程的时候,它会帮你配置好各种东西,如springmvc的相关配置,以及内嵌tomcat等等,这使得开发人员不需要而外再

    浪费精力。用官网的一句话来描述:

    Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".
    We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need minimal Spring configuration.

      相比于使用SpringMVC + Maven的方式去构建一个web项目,用springboot就非常的简单,而且很快。其实springboot之所能够如此简单快捷,还得归功于spring注解驱动的发展,

    在springboot项目中,我们会使用到各种注解。

    Spring 注解驱动的发展过程

    spring 1.x

      在SpringFramework1.x时代,其中在1.2.0是这个时代的分水岭,当时Java5刚刚发布,业界正兴起了使用Annotation的技术风,Spring Framework自然也提供了支持,比如当时已经
    支持了@Transactional等注解,但是这个时候,XML配置方式还是唯一选择。我们经常使用的就是配置各种对象实例:
    <bean name="" class=""/>

    在项目初期,需要管理的对象不多的时候,这种配置很好用,但是随着项目的发展,需要管理的对象会越来越多,配置起来就会很麻烦,这让我想起很久之前做过的一个项目就是如此,经常一轮

    需要下来需要配置二十多个对象,经常还会和同事的配置产生冲突,每次都需要浪费精力去修改很是麻烦。

    Spring 2.x

      Spring Framework2.x时代,2.0版本在Annotation中添加了@Required、@Repository以及AOP相关的@Aspect等注解,同时也提升了XML配置能力,也就是可扩展的XML,比如Dubbo这样的开源框架就
    是基于Spring XML的扩展来完美的集成Spring,从而降低了Dubbo使用的门槛。在2.x时代,2.5版本也是这个时代的分水岭, 它引入了一些很核心的Annotation
    • Autowired 依赖注入
    • @Qualififier 依赖查找
    • @Component、@Service 组件声明
    • @Controller、@RequestMappring等spring mvc的注解
    尽管Spring 2.x时代提供了不少的注解,但是仍然没有脱离XML配置驱动,比如context:annotation-confifig context:componet-scan , 前者的职责是注册Annotation处理器,后者是负责扫描classpath下指定
    包路径下被Spring模式注解标注的类,将他们注册成为Spring Bean @Required/ @Repository(Dao)/@Aspect

    spring 3.x版本

      Spring Framework3.0是一个里程碑式的时代,他的功能特性开始出现了非常大的扩展,比如全面拥抱Java5、以及Spring Annotation。更重要的是,它提供了配置类注解@Confifiguration, 他出现的首要
    任务就是取代XML配置方式。
  • 相关阅读:
    remove white space from read
    optimize the access speed of django website
    dowload image from requests
    run jupyter from command
    crawl wechat page
    python version 2.7 required which was not found in the registry windows 7
    health
    alternate rows shading using conditional formatting
    word
    【JAVA基础】static 关键字
  • 原文地址:https://www.cnblogs.com/talkingcat/p/13679230.html
Copyright © 2011-2022 走看看