SpringBoot起步

1.SpringBoot依赖包导入

方式一:将spring-boot的依赖为父pom出现

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.6.RELEASE</version>
</parent>

方式二:以依赖引用的形式进行SpringBoot依赖库的配置:

<properties>
     <spring-boot.version>2.1.6.RELEASE</spring-boot.version>
</properties> 
<packaging>pom</packaging>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot</artifactId>
                <version>${spring-boot.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

二,新建一个子模块micro-base

1.引入SpringBoot核心依赖库

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

2.编写一个测试Action类,注意注解

 1 import org.springframework.stereotype.Controller;
 2 import org.springframework.web.bind.annotation.RequestMapping;
 3 import org.springframework.web.bind.annotation.ResponseBody;
 4 @Controller
 5 public class MessageAction {
 6     @ResponseBody
 7     @RequestMapping("/")
 8         public String echo() {
 9         return "你好,这是第一个SpringBoot程序";
10         }
11 }

3.在micro-base下创建程序启动主类

1 package com.lion;
2 import org.springframework.boot.SpringApplication;
3 import org.springframework.boot.autoconfigure.SpringBootApplication;
4 @SpringBootApplication
5 public class StartBootMain {
6     public static void main(String[] args) {
7         SpringApplication.run(StartBootMain.class, args);
8     }
9 }

4.然后启动程序主类,访问http://localhost:8080,一个基础的MVC开发应用实现。

5.SpringBoot追求的是零配置,但是我们也可以自定义spring配置文件,在程序主类里使用“@import”注解导入

@Import("classpath:spring/spring-xx.xml")

 

posted @ 2019-08-05 11:28  萧余  阅读(182)  评论(0编辑  收藏  举报