首页 > 编程语言 > 详细

SpringBoot

时间:2018-05-29 01:22:41      阅读:283      评论:0      收藏:0      [点我收藏+]

一个功能
浏览器发送hello请求,服务器接受请求并处理,响应Hello World字符串.
1.创建一个maven工程;(jar)
2.导入依赖Spring Boot相关的依赖

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

  

3.编写一个主程序;启动Spring Boot应用
4.编写相关Controller、Service

package hello;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

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

  

5.运行主程序测试
6.简化部署

pox.xml配置

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

可以将应用打包生成一个可执行的jar包

SpringBoot

原文:https://www.cnblogs.com/cykj/p/SpringBoot.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!