在Heroku上托管Spring应用程序时出现白标错误页面

zd287kbt  于 2022-11-13  发布在  Spring
关注(0)|答案(1)|浏览(109)

Sping Boot 应用程序通过GitHub在Heroku上成功构建,但在转到URL时不断出现此错误。我一辈子都搞不清楚这个问题。

Heroku日志

2022-09-14T16:22:58.876311+00:00 app[web.1]: 2022-09-14 16:22:58.876  INFO 4 --- [nio-4993-exec-3] o.s.web.servlet.DispatcherServlet: Completed initialization in 3 ms
2022-09-14T16:22:59.016296+00:00 heroku[router]: at=info method=GET path="/" host=tr-tribute-page.herokuapp.com request_id=a3c60943-14ed-49da-aafc-40e42a2bc4b2 fwd="24.185.150.106" dyno=web.1 connect=0ms service=250ms status=404 bytes=522 protocol=https
2022-09-14T16:23:03.337945+00:00 heroku[router]: at=info method=GET path="/tribute" host=tr-tribute-page.herokuapp.com request_id=a8104886-18db-4209-9727-6b1084eb7d0b fwd="24.185.150.106" dyno=web.1 connect=0ms service=30ms status=404 bytes=433 protocol=https
2022-09-14T16:23:06.542571+00:00 heroku[router]: at=info method=GET path="/tribute" host=tr-tribute-page.herokuapp.com request_id=9575a8d7-88b3-4cf8-971d-f31dc321cdaf fwd="24.185.150.106" dyno=web.1 connect=0ms service=19ms status=404 bytes=433 protocol=https
2022-09-14T16:23:07.166044+00:00 heroku[router]: at=info method=GET path="/tribute" host=tr-tribute-page.herokuapp.com request_id=f5adb70a-fd2b-4bd7-a0e2-e44cc9c1030e fwd="24.185.150.106" dyno=web.1 connect=0ms service=24ms status=404 bytes=433 protocol=https
2022-09-14T16:23:07.526252+00:00 heroku[router]: at=info method=GET path="/tribute" host=tr-tribute-page.herokuapp.com request_id=b6d03160-7f6b-4764-b810-0c0d37d80279 fwd="24.185.150.106" dyno=web.1 connect=0ms service=13ms status=404 bytes=433 protocol=https
2022-09-14T16:23:07.873937+00:00 heroku[router]: at=info method=GET path="/tribute" host=tr-tribute-page.herokuapp.com request_id=37df3ba3-ffa3-4ffa-9b5b-dab06d657bee fwd="24.185.150.106" dyno=web.1 connect=0ms service=17ms status=404 bytes=433 protocol=https
2022-09-14T16:23:08.091635+00:00 heroku[router]: at=info method=GET path="/tribute" host=tr-tribute-page.herokuapp.com request_id=126d0df7-f9b3-489f-a4d1-6f2892725573 fwd="24.185.150.106" dyno=web.1 connect=0ms service=28ms status=404 bytes=433 protocol=https
2022-09-14T16:23:08.242115+00:00 heroku[router]: at=info method=GET path="/tribute" host=tr-tribute-page.herokuapp.com request_id=f82735d4-6006-4788-9d60-b0f505437cb5 fwd="24.185.150.106" dyno=web.1 connect=0ms service=9ms status=404 bytes=433 protocol=https
2022-09-14T16:33:59.047100+00:00 heroku[router]: at=info method=GET path="/" host=tr-tribute-page.herokuapp.com request_id=9bb4d029-c514-46aa-8eb2-0066e026700d fwd="24.185.150.106" dyno=web.1 connect=0ms service=30ms status=404 bytes=522 protocol=https

控制器类别

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {
    
    @RequestMapping("tribute")
    public String getHome() {
        return "home";
    }

}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.3</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.tribute</groupId>
    <artifactId>tribute</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>TributePage</name>
    <description>Theodore Roosevelt Tribute Page</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>jakarta.servlet.jsp.jstl</groupId>
            <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>glassfish-jstl</artifactId>
            <version>11.0.11</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>5.1.3</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

home.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<link href="webjars/bootstrap/5.1.3/css/bootstrap.min.css"
    rel="stylesheet">
<link
    href="webjars/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.standalone.min.css"
    rel="stylesheet">
<title>Theodore Roosevelt Tribute Page</title>
</head>
<body class="container" style="background-color: LightGray;">
    <div style="text-align: center;">
        <h1 class="display-1">
            <strong>Theodore Roosevelt</strong>
        </h1>
        <p style="font-size: 2rem">The Rough Rider</p>
        <figure class="figure">
            <img src="images/tribute.jpg" height="600" width="500">
            <figcaption class="figure-caption">Theodore Roosevelt,
                1904</figcaption>
        </figure>
    </div>
    <br>
    <div
        style="max-width: 900px; margin: 0 auto 50px auto; text-align: left; line-height: 1.8;">
        <h3>Timeline of Theodore Roosevelts life:</h3>
        <br>
        <ul>
            <li><strong>1858</strong> - Theodore Roosevelt is born at 28
                East 20th Street, New York, NY</li>
            <li><strong>1876</strong> - Attends Harvard University studying
                history and government</li>
            <li><strong>1880</strong> - Marries Alice Hathaway Lee</li>
            <li><strong>1881</strong> - Elected to New York State Assembly
                at the age of 23</li>
            <li><strong>1884</strong> - Wife Alice and mother die, only
                hours apart. Moves to the Dakota Territories</li>
            <li><strong>1886</strong> - Marries childhood friend Edith
                Kermit Carow</li>
            <li><strong>1889</strong> - Starts as U.S. Civil Service
                Commissioner in Washington, DC</li>
            <li><strong>1895</strong> - Becomes Police Commissioner of New
                York City and is later elected President of the Board of Police
                Commissioners. Receives national attention for police reforms in New
                York City</li>
            <li><strong>1897</strong> - Appointed Assistant Secretary of the
                Navy</li>
            <li><strong>1898</strong> - Becomes a war hero after leading a
                regiment of calvary known as "Rough Riders" in Cuba during the
                Spanish-American War. Then in November is elected Governor of New
                York</li>
            <li><strong>1900</strong> - Elected U.S. vice-president under
                President William McKinley</li>
            <li><strong>1901</strong> - Roosevelt becomes the youngest U.S.
                president after the assassination of William McKinley</li>
            <li><strong>1902</strong> - Establishes Crater Lake National
                Park, the first of five parks founded during his presidency.</li>
            <li><strong>1904</strong> - Issues "Roosevelt Corollary" to
                Monroe Doctrine, arguing that the U.S. can act as "an international
                police power" and intervene in Latin America</li>
            <li><strong>1905</strong> - Establishes National Forest Service</li>
            <li><strong>1906</strong> - Awarded Nobel Peace Prize for
                facilitating negotiations that end Russo-Japanese War</li>
            <li><strong>1907</strong> - Signs Immigration Act of 1907, which
                allows president to restrict number of immigrants from Japan</li>
            <li><strong>1909</strong> - Presidency ends; Roosevelt and his
                son Kermit spend a year on safari with the Smithsonian-Roosevelt
                African Expedition</li>
            <li><strong>1912</strong> - Nominated as presidential candidate
                of Progressive party (Bull Moose party). Shot in the chest before
                campaign speech. Finishes the speech before receiving medical
                attention</li>
            <li><strong>1914</strong> - Goes on expedition to explore an
                uncharted tibutary of Amazon River. Injures leg severely during
                expedition aand nearly dies</li>
            <li><strong>1918</strong> - Publishes "The Great Adventure"</li>
            <li><strong>1919</strong> - Dies in sleep at Sagamore Hill of a
                coronary embolism at age 60</li>
        </ul>
    </div>
    <div style="text-align: center">
        <blockquote class="blockquote">
            <em>"Speak softly and carry a big stick; you will go far"
                -Theodore Roosevelt</em>
        </blockquote>
        <br>
        <h3>
            Read more about Theodore Roosevelt at his <a
                href="https://en.wikipedia.org/wiki/Theodore_Roosevelt">Wikipedia
                page.</a>
        </h3>
    </div>
    <hr>
    <footer style="padding-bottom: 1.5rem">
        <small>&copy; 2022 - TheodoreRooseveltTribute</small>
    </footer>
    <script src="webjars/bootstrap/5.1.3/js/bootstrap.min.js"></script>
    <script src="webjars/jquery/3.6.0/jquery.min.js"></script>
    <script
        src="webjars/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
</body>
</html>
5vf7fwbs

5vf7fwbs1#

我觉得这个行,

@RequestMapping("/tribute")
public String getHome() {
    return "home";
}

相关问题