簡體   English   中英

如何修復heroku Web應用程序上的錯誤404

[英]How to fix error 404 on heroku web application

我的 web 應用程序是用 java 構建的,它在 tomcat server 9.0 上運行 在 localhost 上它工作正常,但在將它部署到 heroku 后我收到了這個錯誤。 構建和部署成功。

HTTP 狀態 404 – 未找到

類型狀態報告

信息 /

描述 源服務器沒有找到目標資源的當前表示,或者不願意透露一個存在。

當我嘗試訪問我的 heroku 網絡應用程序時出現此錯誤。

網頁.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
    version="4.0">
    
    <welcome-file-list>
        <welcome-file>home.jsp</welcome-file>
    </welcome-file-list>
    
</web-app>

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>prototype_upgradecareer.github.io</groupId>
  <artifactId>prototype_upgradecareer.github.io</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.3</version>
      </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals><goal>copy-dependencies</goal></goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals><goal>copy</goal></goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.heroku</groupId>
                                <artifactId>webapp-runner</artifactId>
                                <version>9.0.30.0</version>
                                <destFileName>webapp-runner.jar</destFileName>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    
  </build>
  <dependencies>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.19</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
    <scope>provided</scope>
</dependency>
  </dependencies>
  
</project>

配置文件

web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war

我嘗試使用 heroku 控制台(在 heroku.com 中)檢查目標文件夾,這是成功構建后的列表在此處輸入圖片說明

在日志上,除此之外,一切似乎都很好

2020-08-24T12:05:27.612061+00:00 app[web.1]: INFO: No global web.xml found
2020-08-24T12:05:27.710152+00:00 heroku[web.1]: State changed from starting to up
2020-08-24T12:05:30.862409+00:00 app[web.1]: Aug 24, 2020 12:05:30 PM org.apache.jasper.servlet.TldScanner scanJars
2020-08-24T12:05:30.862421+00:00 app[web.1]: INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2020-08-24T12:05:30.945571+00:00 app[web.1]: Aug 24, 2020 12:05:30 PM org.apache.coyote.AbstractProtocol start
2020-08-24T12:05:30.945574+00:00 app[web.1]: INFO: Starting ProtocolHandler ["http-nio-51544"]
2020-08-24T12:05:37.009304+00:00 heroku[router]: at=info method=GET path="/" host=upgradecareer.herokuapp.com request_id=d13362d6-0a53-4890-b2e9-949882b80fb1 fwd="106.215.199.53" dyno=web.1 connect=0ms service=51ms status=404 bytes=864 protocol=https
^C^CThe system cannot find message text for message number 0x237b in the message file for Application.

我的org.eclipse.wst.common.component文件

<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
    <wb-module deploy-name="prot**********">
        <wb-resource deploy-path="/" source-path="/"/>
        <wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
        <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
        <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
        <property name="context-root" value="pro************"/>
        <property name="java-output-path" value="/pro***********/build/classes"/>
    </wb-module>
</project-modules

我嘗試重新啟動 dyno 仍然沒有運氣。

我意識到這個問題不再活躍,但在 Heroku 上遇到了類似的問題。

結果證明是CORS問題。 我使用了 Spring Boot,所以我通過使用解決了我的問題

@CrossOrigin(origins = "*")

在我的 RESTController 上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM