一、起步

  1.先导

    凡技术必登其官网的原则,官网走一波https://projects.spring.io/spring-boot/#quick-start

     极力推荐一个springboot教程https://gitee.com/didispace/SpringBoot-Learning

  2.springboot优点

    官网原版:

  

Features

  • Create stand-alone Spring applications
  • Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
  • Provide opinionated 'starter' POMs to simplify your Maven configuration
  • Automatically configure Spring whenever possible
  • Provide production-ready features such as metrics, health checks and externalized configuration
  • Absolutely no code generation and no requirement for XML configuration

  翻译:

特征

  • 创建独立的Spring应用程序
  • 直接嵌入Tomcat,Jetty或Undertow(无需部署WAR文件)
  • 提供自己的“入门”POM来简化您的Maven配置
  • 尽可能自动配置Spring
  • 提供生产就绪功能,如指标,运行状况检查和外部配置
  • 绝对不会生成代码也不需要XML配置

二、第一个HelloWorld程序

    1.网页工具产生脚手架

      参考http://blog.didispace.com/spring-boot-learning-1/

      使用eclipse的话,通过sts的new->spring starter project也是OK的

    2.使用IDEA内嵌Spring Initializr

      File==>New==>Project,选择Spring Initializr,地址指向官网的initial地址,这里较新版本的IDEA已经提供了默认Url:

      springboot快速入门(一)——HelloWorld搭建

      点击 Next 来到工程信息窗口;主要有2点需要调整的地方:Type可选择maven/gradle,语言可选择Java/Kotliln等,这里我们调整2项工程

的基本信息,其他保持默认。实际创建时根据需要调整信息:

      springboot快速入门(一)——HelloWorld搭建

      点击 Next,来到springboot版本选择和依赖管理界面,其中,依赖不仅包含了springboot的依赖,还包括spring cloud的依赖,这里由于是Hello World,我们只勾选springboot的版本和web这个依赖:

      springboot快速入门(一)——HelloWorld搭建

      点击 Next,选择工程的一些保存路径等就OK了:(老规矩,路径请勿带中文和空格!)

      springboot快速入门(一)——HelloWorld搭建

      点击 Finish就完成工程创建了,如果是第一次创建,将会下载大量的依赖jar,请稍等片刻!

     如果没有配置maven的仓库,请参考maven随笔,配置为阿里云仓库

    3.工程介绍

      工程完成后,可以适当删除一些不需要的文件:

      springboot快速入门(一)——HelloWorld搭建

      默认的pom如下:

      主要包括一个parent依赖,一个web必备的依赖以及一个单元测试的test依赖,还有打包插件以及其他项目信息等

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>springboot_demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>
pom.xml

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2021-06-01
  • 2019-01-22
  • 2021-11-02
  • 2021-04-19
  • 2022-12-23
猜你喜欢
  • 2021-07-23
  • 2021-09-24
  • 2021-11-15
  • 2021-04-14
相关资源
相似解决方案