1、承接上一讲,一个spring boot 项目如果没有application.properties文件,也是可以正常运行的,因为spring boot默认配置了运行参数,但是项目中往往不会用默认的配置,这个时候就要给spring boot 项目新建一个application.properties。
#占用的web端口,默认端口8080
server.port=60000
#项目路径,默认为当前路径,spring boot2.0以后才是这个配置
server.servlet.context-path=/springbootstudy
#日志打印级别为debug,默认为info级别
logging.level.com.tansitao=DEBUG
通过这几个简单的配置,运行起来后的项目就占用的是端口60000,项目路径就是端口后加上/springbootstudy,日志也能打印debug级别以上的日志了
2、写一个contrallor
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(“springboot”)
public class MyController {
@RequestMapping("hello")
public String hello(){
System.out.println("hello word");
return "hello word!";
}
}
第一个spring boot的接口就这么诞生了,没有复杂的xml,就是这么简单