为什么我在运行简单的 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 错误页面 的相关文章

  • 将SQL数据引入jquery availabletag

    我正在尝试制作自动完成文本框 但如何将 SQL 数据包含到 jquery 可用标记并循环它 我无法根据以下代码执行该功能 任何帮助 将不胜感激 谢谢 这是我的预期输出 预期结果演示 http jsfiddle net VvETA 71 jq
  • 埃拉托色尼筛法 - 实现返回一些非质数值?

    我用 Java 实现了埃拉托斯特尼筛法 通过伪代码 public static void sieveofEratosthenes int n boolean numArray numArray new boolean n for int i
  • 在 Struts 2 中传递 URL 参数而不使用查询字符串

    我想使用类似的 URL host ActionName 123 abc 而不是像这样传递查询字符串 host ActionName parm1 123 parm2 abc 我怎样才能在 Struts 2 中做到这一点 我按照下面的方法做了
  • tomcat 7.0.50 java websocket 实现给出 404 错误

    我正在尝试使用 Java Websocket API 1 0 JSR 356 中指定的带注释端点在 tomcat 7 0 50 上实现 websocket 以下是我如何对其进行编码的简要步骤 1 使用 ServerEndpoint注解编写w
  • 为什么Iterator接口没有add方法

    In IteratorSun 添加了remove 方法来删 除集合中最后访问的元素 为什么没有add方法来向集合中添加新元素 它可能对集合或迭代器产生什么样的副作用 好的 我们开始吧 设计常见问题解答中明确给出了答案 为什么不提供 Iter
  • 如何使用正则表达式验证 1-99 范围?

    我需要验证一些用户输入 以确保输入的数字在 1 99 范围内 含 这些必须是整数 Integer 值 允许前面加 0 但可选 有效值 1 01 10 99 09 无效值 0 007 100 10 5 010 到目前为止 我已经制定了以下正则
  • 当 minifyEnabled 为 true 时 Android 应用程序崩溃

    我正在使用多模块应用程序 并且该应用程序崩溃时minifyEnabled true in the installed模块的build gradle 以下是从游戏控制台检索到的反混淆堆栈跟踪 FATAL EXCEPTION Controlle
  • 通过 appassembler-maven-plugin 生成的脚本无法在 Spring Boot 应用程序中找到主类

    我使用 appassembler maven plugin 生成的启动脚本有问题 我有一个基本的 spring boot 应用程序 只有一个类 SpringBootApplication public class ScriptDemoApp
  • 我们如何测试包私有类?

    我正在看书Effective Java in Item 13 Minimize the accessibility of classes and members 它提到 为了方便测试 您可能想让类 接口或成员更易于访问 这在某种程度上是好的
  • 如何停止执行的 Jar 文件

    这感觉像是一个愚蠢的问题 但我似乎无法弄清楚 当我在 Windows 上运行 jar 文件时 它不会出现在任务管理器进程中 我怎样才能终止它 我已经尝试过 TASKKILL 但它对我也不起作用 On Linux ps ef grep jav
  • JAVA中遍历JSON数据

    我是 JSON 新手 我使用 HTTPUrlConnections 并在 JAVA 程序中获得一些响应 响应数据将类似于 data id 1 userId 1 name ABC modified 2014 12 04 created 201
  • Java - 从 XML 文件读取注释

    我必须从 XML 文件中提取注释 我找不到使用 JDOM 或其他东西来让它们使用的方法 目前我使用 Regex 和 FileReader 但我不认为这是正确的方法 您可以使用 JDOM 之类的东西从 XML 文件中获取注释吗 或者它仅限于元
  • 避免 Java 中的重复导入:继承导入?

    有没有办法 继承 导入 Example 常见枚举 public enum Constant ONE TWO THREE 使用此枚举的基类 public class Base protected void register Constant
  • Lombok @Builder 不创建不可变对象?

    在很多网站上 我看到 lombok Builder 可以用来创建不可变的对象 https www baeldung com lombok builder singular https www baeldung com lombok buil
  • 禁用 Android 菜单组

    我尝试使用以下代码禁用菜单组 但它不起作用 菜单项仍然启用 你能告诉我出了什么问题吗 资源 菜单 menu xml menu menu
  • 使用 Java https 上传到 Imgur v3 错误

    我目前正在尝试使用他们当前的 API v3 上传到 imgur 但是我不断收到错误 错误 javax net ssl SSLException 证书中的主机名不匹配 api imgur com imgur com OR imgur com
  • 何时在 hibernate 中使用 DiscriminatorValue 注解

    在 hibernate 中使用 DiscriminatorValue 注释的最佳场景是什么以及何时 这两个链接最能帮助我理解继承概念 http docs oracle com javaee 6 tutorial doc bnbqn html
  • HttpClient请求设置属性问题

    我使用这个 HttpClient 库玩了一段时间 几周 我想以某种方式将属性设置为请求 不是参数而是属性 在我的 servlet 中 我想使用 Integer inte Integer request getAttribute obj 我不
  • 检查应用程序是否在 Android Market 上可用

    给定 Android 应用程序 ID 包名称 如何以编程方式检查该应用程序是否在 Android Market 上可用 例如 com rovio angrybirds 可用 而 com random app ibuilt 不可用 我计划从
  • 如何使用通配符模拟泛型方法的行为

    我正在使用 EasyMock 3 2 我想基于 Spring Security 为我的部分安全系统编写一个测试 我想嘲笑Authentication http docs spring io autorepo docs spring secu

随机推荐

  • 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