springboot 设置项目路劲后不能访问首页

环境背景

学习版本 : springboot2.31 

controller  代码 

@controller
public class  Iindex{

    @RequestMapping(“/”)
    public String  index(){
         return “/index”  
    }    
}

  

开始没有设置 server.servlet.context-path 值得时候,访问localhost :8080  正常访问  index 方法  。 后来设置 了 项目路径   server.servlet.context-path=/content  。再访问localhost:8080/content 的时候 不能访问到index  方法 。 

解决方法

  把  @controller  改成@ RestController  注解 。

总结

  这个不知道到是不是高版本后的修改  ,在springboot1.5  的时候  使用 @Controller 和 @RequestMapMapping  没有这个问题。 

  在高版本后设置 项目的路劲由之前的server.content-path=xxxxxx  改为了server.servlet.content-path=xxxxxxx 

原文地址:https://www.cnblogs.com/jonrain0625/p/13334240.html