1.maven工程下的dependency(注:如果你已经有父model,那就把parent的那些放在父model上,升级成爷爷辈)
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
2.代码如下:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@EnableAutoConfiguration
public class hello{
@GetMapping("/")
@ResponseBody
String home(){
return "hello";
}
public static void main(String[]s){
SpringApplication.run(hello.class,s);
}
}
3.在application.yaml文件里面可以配置端口号:
server:
port:9999
4.直接运行就可以启动了,在浏览器里面输入localhost:9999/就ok,端口号默认是8080