【发布时间】:2020-12-13 02:29:44
【问题描述】:
我的 web 应用程序是用 java 构建的,它在 tomcat server 9.0 上运行 在 localhost 上它工作正常,但在将它部署到 heroku 后,我收到了这个错误。构建和部署成功。
HTTP 状态 404 - 未找到
类型状态报告
留言/
描述 源服务器没有找到当前的表示 对于目标资源或不愿意透露存在的资源。
当我尝试访问我的 heroku 网络应用程序时遇到此错误。
Web.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
<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 仍然没有运气。
【问题讨论】:
-
您确定您的 Api 基本路径是
/吗?检查您使用的方法。也许它需要先调用选项? -
我不知道那是什么。
-
@dbl 我添加了有问题的 org.eclipse.wst.common.component 文件。我希望它包含该数据
-
尝试找出答案:) 我也不熟悉
heroku,但 404 通常意味着它所说的 - 找不到资源(地址错误)。当您可以按域访问资源时,基本路径是/,没有任何路径说明符 -https://localhost。如果您的基本路径是/api,那么应该通过https://localhost/api/访问基本路径...方法是post、get(在您的示例中)等... -
只有它的根'/'。我在 localhost 上使用 tomcat 的 Web 应用程序运行良好。仅在将其部署到heroku后,我才遇到此问题。构建成功并成功部署。我也尝试了不同的路径,例如 myapp.heroku.com/home.jsp 和其他位置。仍然到处都是 404。
标签: java tomcat heroku web-applications