简体   繁体   English

如何修复heroku Web应用程序上的错误404

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

My web application is built with java and its running on tomcat server 9.0 On localhost its working fine but after deploying it to heroku I am getting this error.我的 web 应用程序是用 java 构建的,它在 tomcat server 9.0 上运行 在 localhost 上它工作正常,但在将它部署到 heroku 后我收到了这个错误。 Build and deployment was successful.构建和部署成功。

HTTP Status 404 – Not Found HTTP 状态 404 – 未找到

Type Status Report类型状态报告

Message /信息 /

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.描述 源服务器没有找到目标资源的当前表示,或者不愿意透露一个存在。

I am getting this error when I am trying to access my heroku web app.当我尝试访问我的 heroku 网络应用程序时出现此错误。

Web.xml网页.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>

Pom.xml 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>

Procfile配置文件

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

I tried to check the target folder using heroku console(in heroku.com) here are list after successful builds我尝试使用 heroku 控制台(在 heroku.com 中)检查目标文件夹,这是成功构建后的列表在此处输入图片说明

On logs everything seems fine except for this在日志上,除此之外,一切似乎都很好

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.

My org.eclipse.wst.common.component file我的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

I tried restarting dyno still no luck.我尝试重新启动 dyno 仍然没有运气。

I realized this issue is no longer active but encountered a similar issue on Heroku.我意识到这个问题不再活跃,但在 Heroku 上遇到了类似的问题。

It turned out to be a CORS issue.结果证明是CORS问题。 I used Spring boot so I resolved my issue by using我使用了 Spring Boot,所以我通过使用解决了我的问题

@CrossOrigin(origins = "*")

on my RESTControllers.在我的 RESTController 上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM