1.spring boot 入门 starter(启动器)

1.Spring boot helloword

1.启动类

 //启动器
    @SpringBootApplication
    public class ResgiterApp {
        public static void main(String[] args){
            //启动注册中心
            SpringApplication.run(ResgiterApp.class,args);
        }
    }

2.跳转类

   //标识为controller
    @Controller
    public class Say{
        @RequestMapping("/sayHello")
        @ResponseBody
        public String sayHello(){
            return "hello word";
        }
    } 

3.pom.xml

   <?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.limit</groupId>
        <artifactId>spring boot</artifactId>
        <version>1.0-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.13.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>    
    </project>

4.项目部署

1.在Pom文件中添加该插件

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

2.使用mvn clean package 将项目打包

3.使用java -jar即可运行该程序

4.Spring boot Strart(启动器)

2.Spring boot start 启动器原理

1.Spring boot Strart parent

    <!--所有Spring boot 项目都依赖于Spring boot Strart parent -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
    </parent>

2.Spring boot dependencies

该依赖声明了spring boot 项目需要的一些依赖的版本

    <!--Spring boot starter parent 又依赖于Spring boot dependencies -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath>../../spring-boot-dependencies</relativePath>
    </parent>
    <!--该依赖中的properties声明了spring boot项目依赖的jar包的版本信息,所以在该处已经声明的信息不需要在在你项目的pom 文件中声明 -->

3.Spring boot start web web项目启动器

该依赖引入了web项目所需要的jar包

    <!--所有的jar包都是由start启动器引入的-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
posted @ 2018-05-23 13:52  大于吃小于  阅读(245)  评论(0编辑  收藏  举报