springboot server.context-path=/springboot配置不生效
@RestController
public class Hellocontroller {
@RequestMapping("/hello")
public String hello(){
return "this is my configuration files test project";
}
}
原本浏览器输入localhost:8082/hello即可访问,然后在配置文件中加入
配置项目的访问路径
server.context-path= /springboot
发现还是可以继续访问,这样说明配置并没有生效。然后将配置改为
配置项目的访问路径
server.servlet.context-path= /springboot
配置生效,输入localhost:8082/hello不可访问,输入localhost:8082/springboot/hello访问成功。以上问题只是因为版本问题,在spring boot2.0之前,上下文的配置为server.context-path。而spring boot2.0之后,上下文的配置改为了server.servlet.context-path。我的springboot版本号为2.3.3。