为什么我在运行简单的 Spring Boot 应用程序时总是收到状态为“404”的 Whitelabel 错误页面

2024-03-19

我的控制器

@Controller
//@RequestMapping("/")
//@ComponentScan("com.spring")
//@EnableAutoConfiguration
public class HomeController {

    @Value("${framework.welcomeMessage}")
    private String message;

    @RequestMapping("/hello")
    String home(ModelMap model) {
        System.out.println("hittin the controller...");
        model.addAttribute("welcomeMessage", "vsdfgfgd");
        return "Hello World!";
    }

    @RequestMapping(value = "/indexPage", method = RequestMethod.GET)
    String index(ModelMap model) {
        System.out.println("hittin the index controller...");
        model.addAttribute("welcomeMessage", message);
        return "welcome";
    }

    @RequestMapping(value = "/indexPageWithModel", method = RequestMethod.GET)
    ModelAndView indexModel(ModelMap model) {
        System.out.println("hittin the indexPageWithModel controller...");
        model.addAttribute("welcomeMessage", message);
        return new ModelAndView("welcome", model);
    }
}

我的 JSP (welcome.jsp) 位于 /WEB-INF/jsp 内(父文件夹是WebContent)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome to Spring Boot</title>
</head>

<body>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
Message: ${message}
</body>
</html>

我的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>SpringBootPlay</groupId>
    <artifactId>SpringBootPlay</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>com.jcabi</groupId>
            <artifactId>jcabi-log</artifactId>
            <version>0.17</version>
        </dependency>
    </dependencies>
    <properties>
        <java.version>1.8</java.version>
        <start-class>com.spring.play.BootLoader</start-class>
        <main.basedir>${basedir}/../..</main.basedir>
        <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <useSystemClassLoader>false</useSystemClassLoader>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我的应用程序初始化程序

@EnableAutoConfiguration
@SpringBootApplication
@ComponentScan({ "com.spring.controller" })
@PropertySources(value = { @PropertySource("classpath:/application.properties") })
public class BootLoader extends SpringBootServletInitializer {

    final static Logger logger = Logger.getLogger(BootLoader.class);

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(BootLoader.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(BootLoader.class, args);
    }
}

我什至添加了thymeleaf对我的 pom 的依赖。还是没用。每当我击中localhost:8080/hello or /indexPage or /indexPageWithModel它总是说

白标错误页面

此应用程序没有 /error 的显式映射,因此您将其视为后备。

2016 年美国东部时间 9 月 21 日星期三 21:34:18 出现意外错误(类型=未找到,状态=404)。 ]/WEB-INF/jsp/welcome.jsp

我的应用程序属性

spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
framework.welcomeMessage=Welcome to Dashboard

请帮我。谢谢!


这是几乎所有 Spring Boot 初学者都会遇到的最常见错误之一。

解决方案非常简单 - 您的 Bootstrap 类应该知道它应该引用的包或类路径,以便访问组件/控制器。因此,您需要指定如下:-@ComponentScan(basePackages= {"org.test.controller"})

P.S.-这里的“org.test.controller”是我保存控制器的包的限定名称。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么我在运行简单的 Spring Boot 应用程序时总是收到状态为“404”的 Whitelabel 错误页面 的相关文章

  • Pig Udf 显示结果

    我是 Pig 的新手 我用 Java 编写了一个 udf 并且包含了一个 System out println 其中的声明 我必须知道在 Pig 中运行时该语句在哪里打印 假设你的UDF 扩展了 EvalFunc 您可以使用从返回的 Log
  • Java 集合的并集或交集

    建立并集或交集的最简单方法是什么Set在 Java 中 我见过这个简单问题的一些奇怪的解决方案 例如手动迭代这两个集合 最简单的单行解决方案是这样的 set1 addAll set2 Union set1 retainAll set2 In
  • Eclipse Maven Spring 项目 - 错误

    I need help with an error which make me crazy I started to study Java EE and I am going through tutorial on youtube Ever
  • jdbc mysql loginTimeout 不起作用

    有人可以解释一下为什么下面的程序在 3 秒后超时 因为我将其设置为在 3 秒后超时 12秒 我特意关闭了mysql服务器来测试mysql服务器无法访问的这种场景 import java sql Connection import java
  • 像 Java 这样的静态类型语言中动态方法解析背后的原因是什么

    我对 Java 中引用变量的动态 静态类型和动态方法解析的概念有点困惑 考虑 public class Types Override public boolean equals Object obj System out println i
  • 内部类的构造函数引用在运行时失败并出现VerifyError

    我正在使用 lambda 为内部类构造函数创建供应商ctx gt new SpectatorSwitcher ctx IntelliJ建议我将其更改为SpectatorSwitcher new反而 SpectatorSwitcher 是我正
  • tomcat 中受密码保护的应用程序

    我正在使用 JSP Servlet 开发一个Web应用程序 并且我使用了Tomcat 7 0 33 as a web container 所以我的要求是tomcat中的每个应用程序都会password像受保护的manager applica
  • 如何对不同的参数类型使用相同的java方法?

    我的问题 我有 2 个已定义的记录 创建对象请求 更新对象请求 必须通过实用方法进行验证 由于这两个对象具有相同的字段 因此可以对这两种类型应用相同的验证方法 现在我只是使用两种方法进行重载 但它很冗长 public record Crea
  • 如何在谷歌地图android上显示多个标记

    我想在谷歌地图android上显示带有多个标记的位置 问题是当我运行我的应用程序时 它只显示一个位置 标记 这是我的代码 public class koordinatTask extends AsyncTask
  • 尝试将 Web 服务部署到 TomEE 时出现“找不到...的 appInfo”

    我有一个非常简单的项目 用于培训目的 它是一个 RESTful Web 服务 我使用 js css 和 html 创建了一个客户端 我正在尝试将该服务部署到 TomEE 这是我尝试部署时遇到的错误 我在这里做错了什么 刚刚遇到这个问题 我曾
  • java for windows 中的文件图标叠加

    我正在尝试像 Tortoise SVN 或 Dropbox 一样在文件和文件夹上实现图标叠加 我在网上查了很多资料 但没有找到Java的解决方案 Can anyone help me with this 很抱歉确认您的担忧 但这无法在 Ja
  • 如何使用 jUnit 将测试用例添加到套件中?

    我有 2 个测试类 都扩展了TestCase 每个类都包含一堆针对我的程序运行的单独测试 如何将这两个类 以及它们拥有的所有测试 作为同一套件的一部分执行 我正在使用 jUnit 4 8 在 jUnit4 中你有这样的东西 RunWith
  • Eclipse 启动时崩溃;退出代码=13

    I am trying to work with Eclipse Helios on my x64 machine Im pretty sure now that this problem could occur with any ecli
  • 干净构建 Java 命令行

    我正在使用命令行编译使用 eclipse 编写的项目 如下所示 javac file java 然后运行 java file args here 我将如何运行干净的构建或编译 每当我重新编译时 除非删除所有内容 否则更改不会受到影响 cla
  • 在java中为组合框分配键

    我想添加一个JComboBox在 Swing 中这很简单 但我想为组合中的每个项目分配值 我有以下代码 JComboBox jc1 new JComboBox jc1 addItem a jc1 addItem b jc1 addItem
  • CamcorderProfile.videoCodec 返回错误值

    根据docs https developer android com reference android media CamcorderProfile html 您可以使用CamcorderProfile获取设备默认视频编解码格式 然后将其
  • 使用 svn 1.8.x、subclise 1.10 的 m2e-subclipse 连接器在哪里?

    我读到 m2e 的生产商已经停止生产 svn 1 7 以外的任何版本的 m2e 连接器 Tigris 显然已经填补了维护 m2e subclipse 连接器的空缺 Q1 我的问题是 使用 svn 1 8 x 的 eclipse 更新 url
  • 双枢轴快速排序和快速排序有什么区别?

    我以前从未见过双枢轴快速排序 是快速排序的升级版吗 双枢轴快速排序和快速排序有什么区别 我在 Java 文档中找到了这个 排序算法是双枢轴快速排序 作者 弗拉基米尔 雅罗斯拉夫斯基 乔恩 本特利和约书亚 布洛赫 这个算法 在许多数据集上提供
  • Spring Boot 无法更新 azure cosmos db(MongoDb) 上的分片集合

    我的数据库中存在一个集合 documentDev 其分片键为 dNumber 样本文件 id 12831221wadaee23 dNumber 115 processed false 如果我尝试使用以下命令通过任何查询工具更新此文档 db
  • Spring Rest 和 Jsonp

    我正在尝试让我的 Spring Rest 控制器返回jsonp但我没有快乐 如果我想返回 json 但我有返回的要求 完全相同的代码可以正常工作jsonp我添加了一个转换器 我在网上找到了用于执行 jsonp 转换的源代码 我正在使用 Sp

随机推荐

  • Android Firebase setValue() 权限被拒绝

    这是在 firebase 上定义规则的方式 rules users read true user id write auth uid user id read true 我已经成功地使用 setValue 在我的注册活动中写入了新的用户信息
  • Windows Azure VM (Mac) 为 ios 设备构建 Ionic 应用程序

    我正在使用 Ionic 框架开发 Ionic2 Angular 应用程序 我对 Android 没有任何问题 我的问题是 我可以使用 Windows Azure VM Mac 为 ios 设备构建应用程序吗 I have Win 8 1 O
  • 避免 Xamarin 相机的“确定重试”按钮

    我正在使用来自的相机代码库https github com rasmuschristensen XamarinFormsImageGallery https github com rasmuschristensen XamarinForms
  • 用两个向量排序

    我想知道是否有可能 例如 vector
  • 计算 Pubsub 主题中未确认消息的数量

    我想在来自 pubsub 主题的所有消息都得到确认后执行一项操作 我尝试使用 Stackdriver 监控 API 来衡量 按云区域细分的未确认消息数 但不了解区域过滤器以及为什么需要它 在哪里可以查看我的主题使用的区域 并且由于某种未知的
  • 如何使用 JQL 检索特定状态的问题

    输入 url 或使用curl 运行 例如 https
  • list.count() 与 Counter() 性能

    在尝试查找字符串中一堆字符的频率时 为什么对 4 个不同的字符运行 string count character 4 次会比使用 collections Counter string 产生更快的执行时间 使用 time time 背景 给定
  • 如何在iOS 4中启用后台iPod控件来控制非iPod音乐?

    我想要完成的一个很好的例子是在最新版本的SpotifyiPhone应用程序 Pandora似乎有相同的功能 当 Spotify 在后台时 双击会打开 多任务坞 其中 iPod 控件 播放 暂停 前进等 允许控制 Spotify 的音乐播放
  • 升级到 Grails 2.3.0 时 RESTful 请求缺少参数

    我正在使用 Grails 和 RESTful 来开发我的 Web 应用程序 一切正常 直到我将应用程序升级到 Grails 2 3 这是我的 UrlMappings 我仍然正常发送请求 提交或做一些其他事情 但在 POST PUT 请求中
  • Bash:使用管道运算符时 Trap ERR 不起作用

    我试图将 stdout 和 stderr 中的所有内容记录到日志文件中 并仍然保留控制台 为此 我只是附加 tee a log file log对每一个命令 但是 如果脚本期间发生任何错误 我还想运行自定义命令 为此 我在脚本的开头添加了以
  • 警告:/etc/php/7.0/mods-available 下不存在模块 ini 文件

    我已经从 ubuntu 卸载了 php7 及其所有模块 当我尝试重新安装模块时 每个 php 模块都会出现以下错误 尽管模块已安装 但由于此错误 它未激活并且无法使用他们 有什么办法可以解决这个问题吗 每个模块的错误 安装时 Not rep
  • 来自数据库的实体生成器

    我需要在春天从现有数据库生成基于注释的实体 我尝试过骄傲 但生成的实体没有注释 我如何在基于骄傲的实体中生成注释 或者任何人都可以建议我一个好的实体生成器 我想说我也尝试过spring roo 您可以尝试 Telosys Tools 这是一
  • C++ 有什么方法可以以编程方式检测 POD 结构吗?

    我有存储 POD 结构的数据结构 每个实例化仅存储单个类型 因为它基本上是特定 POD 结构的数组 有时另一个开发人员 将修改这些结构之一 添加或修改数据类型 如果添加非 POD 元素 例如std string 数据结构在运行时崩溃 因为内
  • 如何禁用颤动开关

    在我的帮助屏幕中 我有这个开关 其目的是不执行任何操作 只是按原样显示 但我现在遇到的问题是 即使它没有做任何事情 用户也可以拖动开关 所以我试图弄清楚如何禁用它 以便没有人可以拖动开关按钮 return Container child C
  • C# 中的激活函数列表

    我可以在数学中找到激活函数列表 但在代码中却找不到 所以我想如果应该有这样一个列表的话 这将是代码中放置这样一个列表的正确位置 从这两个链接中算法的翻译开始 https en wikipedia org wiki Activation fu
  • 将进度条改为双倍

    进度条 ProgressBar pb ProgressBar findViewById R id progressbar pb setProgress 0 int k int max pb setMax k int j int cost p
  • 使用reinterpret_cast访问类似“struct {double, int}”的对象

    通过访问对象reinterpret casted 指针和相关的 UB 已经在这里进行了广泛的讨论 阅读问题和答案后 我仍然不确定是否正确使用 POD 类型的未初始化内存 假设我想 模仿 struct double d int i 通过手动为
  • Meteor 1.0 - 为什么“构建应用程序”花费的时间比以前长得多?

    所以我刚刚更新到Meteor 1 0 在本地开发应用程序时 每当我更新任何 js 文件时 构建应用程序都需要大约 15 秒以上的时间 在此期间控制台会显示 正在构建应用程序 尔格 这是 1 0 中的新行为吗 过去需要 1 2 秒才能看到对
  • 无法使用 Maven“mvn package”构建 Guava

    我刚刚阅读了 Guava 并查看了它的源代码 但不知道如何构建它来使用 我使用 mvn package 构建了 jar 文件 但它生成了 Guava GWT 错误 ERROR Failed to execute goal on projec
  • 为什么我在运行简单的 Spring Boot 应用程序时总是收到状态为“404”的 Whitelabel 错误页面

    我的控制器 Controller RequestMapping ComponentScan com spring EnableAutoConfiguration public class HomeController Value frame