直接从网页下载包 :https://start.spring.io/
下载完成之后,在IDEA上导入 导入完成之后目录
backCtrl代码
package com.hwk.springtest.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class backCtrl {
@RequestMapping(value = "/hello",method = RequestMethod.GET)
public String helloSpringBoot(){
return "Hello Spring Boot!";
}
}
之后配置tomcat端口,以防端口占用
最后点击运行就启动服务了
有一点需要注意!!
如果你是第一次使用SpringBoot内嵌的tomcat的话,在pom文件中配置的话,tomcat的依赖需要写在最前面,不然在SpingBoot中tomcat是启动不起来的!!!
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
之后就可以运行了