随笔 - 129  文章 - 7  评论 - 1  阅读 - 11万 

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

1
参考:<a target="_blank">https://projects.spring.io/spring-boot/#quick-start</a>
1
2
3
4
5
6
7
8
9
10
11
<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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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配置

1
2
3
4
5
6
7
8
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

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

posted on 2018-05-28 23:35  互联网开发者  阅读(405)  评论(0)    收藏  举报
点击右上角即可分享
微信分享提示