springboot项目,demo跑起来,可是出现Whitelabel Error Page
问题1:没有创建默认Controller
问题2:创建了Controller但是还是无法访问
问题1解决办法:新建一个java类,加上@Controller注解。
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class IndexController {
@RequestMapping("/")
@ResponseBody
public String test(){
System.out.println("hello world!");
return "hello world!";
}
}
问题2解决办法:创建的controller路径也需要注意,官方规定需要放到启动类Application.java的所在包或者子包下,才能被扫描到,这也是容易忽略的点。
本文介绍了SpringBoot项目运行时出现WhitelabelErrorPage的问题及其解决方案。问题可能在于缺少默认Controller或者Controller未被正确扫描。解决方法包括创建带有@Controller注解的Controller类,并确保Controller位于启动类Application.java的同一包或其子包下,以便于扫描。遵循这些步骤,可以避免SpringBoot启动时的常见错误。
5万+

被折叠的 条评论
为什么被折叠?



