程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Springboot Whitelabel错误页面大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Springboot Whitelabel错误页面?

开发过程中遇到Springboot Whitelabel错误页面的问题如何解决?下面主要结合日常开发的经验,给出你关于Springboot Whitelabel错误页面的解决方法建议,希望对你解决Springboot Whitelabel错误页面有所启发或帮助;

正如您在日志中看到的那样,Spring找不到并注册了您的控制器。可能是因为它属于尚未自动扫描类的软件包。为了解决这个问题,我建议将代码的结构更新为文档中建议的结构。解决该问题的另一种方法是尝试@ComponentScan手动指定。

解决方法

我坚持使用这个简单的MVC示例。当我启动应用程序并转到localhost:8080时,即使在“ src / main / resources /
templates”中创建了“ index.html”,我也得到了“ Whitelabel Error
Page”。我还在索引方法上添加了@requestMapping(“ /”)。我找不到问题。

IndexController.java

package controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.Annotation.requestMapping;
@Controller
public class IndexController {
  @requestMapping("/")
  public String index(){
    return "index";
  }
}

SpringmvcApplication.java

package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringmvcApplication {
  public static void main(String[] args) {
    SpringApplication.run(SpringmvcApplication.class,args);
  }
}

index.html -在“ src / main / resources / templates”下:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
<title>Hello Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>Hello World</h1>
<h2>This is my Thymeleaf index page.</h2>
</body>
</html>

大佬总结

以上是大佬教程为你收集整理的Springboot Whitelabel错误页面全部内容,希望文章能够帮你解决Springboot Whitelabel错误页面所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。