Spring Boot创建项目(Maven)

1、创建一个Maven工程(jar)

  Idea--new project--maven--右边绑定jdk,点击next

  输入项目信息,GroupId,ArtitactId,点击下一步,确认信息,点击完成!

2、导入Spring Boot相关依赖

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

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

3、编写一个主程序

package com.gaofz.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBoot01HelloworldQuickApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringBoot01HelloworldQuickApplication.class, args);
    }

}

4、创建请求controller,service

package com.gaofz.springboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {

    @ResponseBody
    @RequestMapping("/hello")
    public  String hello(){
        return "Hello World quick";
    }
}

5、简化部署

导入插件

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

将这个应用打成jar包,直接使用java -jar命令执行。

 

 

注:Spring Boot场景启动器,spring-boot-starter-web,导入了web模块正常运行所依赖的组件!

posted @ 2019-02-15 11:20  被爱的都有恃无恐  阅读(253)  评论(0编辑  收藏  举报