SpringBoot系列二:搭建自己的第一个SpringBoot程序

一、根据官网手工搭建(http://projects.spring.io/spring-boot/#quick-start)
1、新建一个maven工程springbootfirst

2、 如果要想开发 SpringBoot 程序只需要按照官方给出的要求配置一个父 pom (spring-boot-starter-parent)和添加web开发的支持(spring-boot-starter-web)即可。

1 <project xmlns=“http://maven.apache.org/POM/4.0.0” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance
2 xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
3 4.0.0
4
5 com.study.springboot
6 springbootfirst
7 0.0.1-SNAPSHOT
8 jar
9
10 springbootfirst
11 http://maven.apache.org
12
13
14 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15 <jdk.version>1.8</jdk.version>
16
17
18
19
20 org.springframework.boot
21 spring-boot-starter-parent
22 1.5.4.RELEASE
23
24
25
26
27
28
29 org.springframework.boot
30 spring-boot-starter-web
31
32
33
34
35
36
37 springbootfirst
38
39
40 org.apache.maven.plugins
41 maven-compiler-plugin
42
43 j d k . v e r s i o n &lt; / s o u r c e &gt; &lt; ! − − 源 代 码 使 用 的 开 发 版 本 − − &gt; 44 &lt; t a r g e t &gt; {jdk.version}&lt;/source&gt;&lt;!-- 源代码使用的开发版本 --&gt; 44 &lt;target&gt; jdk.version</source><!使>44<target>{jdk.version}
45 ${project.build.sourceEncoding}
46
47
48
49
50
51

3、 编写一个具体的程序SampleController.java

1 package com.study.springboot.springbootfirst;
2
3 import org.springframework.boot.;
4 import org.springframework.boot.autoconfigure.
;
5 import org.springframework.stereotype.;
6 import org.springframework.web.bind.annotation.
;
7
8 @Controller
9 @EnableAutoConfiguration
10 public class SampleController {
11
12 @RequestMapping("/")
13 @ResponseBody
14 String home() {
15 return “Hello World!”;
16 }
17
18 public static void main(String[] args) throws Exception {
19 SpringApplication.run(SampleController.class, args);
20 }
21 }

4.启动SampleController.java,在浏览器输入http://localhost:8080/即可看到我们使用SpringBoot搭建的第一个web程序成功了,就是这么的快速、简单、方便

二、快速搭建
1、访问http://start.spring.io/
2、选择构建工具Maven Project、Spring Boot版本1.5.11以及一些工程基本信息,点击“Switch to the full version.”java版本选择1.8,可参考下图所示:

3、点击Generate Project下载项目压缩包
4、解压后,使用eclipse,Import -> Existing Maven Projects -> Next ->选择解压后的文件夹-> Finsh,OK done!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值