本文档主要作为本人的备忘录
Spring boot的介绍基本上很容易搜到,这地方我就不多说了,直接介绍使用IDEA创建一个可运行的spring boot项目.
1.File -> New -> Project...
注意一点:将Default: https://start.spring.io 修改为: http://start.spring.io,否则有可能会连接不上
2.Next之后,填写自己的Group,Artifact等,选择Maven Project,Next,Next,Next,
3.最终生成此目录结构,FirstApplication.java 为spring boot的启动类.application.properties为配置文件
4.将 application.properties 修改为 application.yml, 添加配置项
server: port: 8080 #Tomcat端口号 servlet-path: /first #context路径
注意:servlet-path路径前必须带 / 否则会
Caused by: java.lang.IllegalArgumentException: Error page location [first/error] must start with a '/'
5.修改pom.xml,因为这里要创建一个spring web项目,所以需要添加spring-web的依赖
org.springframework.boot spring-boot-starter-web
6.创建一个 FirstController
package com.aulbrother.first.web;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;/** * @since 2018/1/22 9:50 */@RestControllerpublic class FirstController{ @GetMapping("/text") public String text(){ return "success"; }}
7.启动项目
2018-01-22 10:40:42.300 INFO 8928 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup2018-01-22 10:40:42.323 INFO 8928 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)2018-01-22 10:40:42.323 INFO 8928 --- [ main] com.aulbrother.first.FirstApplication : Started FirstApplication in 1.761 seconds (JVM running for 2.559)
8.访问 http://localhost:8080/first/text,成功!!!!
最后贴上完整的pom.xml
4.0.0 com.aulbrother first 0.0.1-SNAPSHOT jar first 第一步 org.springframework.boot spring-boot-starter-parent 1.5.9.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-web org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin