Spring MVC - App适用于本地tomcat,但在部署到heroku时返回404

时间:2018-03-15 21:41:23

标签: java spring heroku

我有一个Spring MVC应用程序,当我在本地tomcat服务器上运行时,它可以正常工作。但是当我将它部署到heroku时,我收到了以下404错误:

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

我正在使用eclipse,我还使用eclipse将我的应用程序部署到heroku

这是我的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>themis</groupId>
  <artifactId>themis</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <properties>
        <spring.version>5.0.3.RELEASE</spring.version>
        <jdk.version>1.8</jdk.version>
    </properties>

    <dependencies>

    <!-- Spring 3 dependencies -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!-- Jackson JSON Mapper -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.9.4</version>
    </dependency>

    <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20090211</version>
    </dependency>

</dependencies>

<build>
    <finalName>SpringMVC</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.9</version>
        <configuration>
            <downloadSources>true</downloadSources>
            <downloadJavadocs>false</downloadJavadocs>
            <wtpversion>2.0</wtpversion>
            <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <source>${jdk.version}</source>
            <target>${jdk.version}</target>
            <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
              <plugin>
            <groupId>com.heroku.sdk</groupId>
            <artifactId>heroku-maven-plugin</artifactId>
            <version>2.0.3</version>
          </plugin>
          <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>
    </plugins>
</build>

这是我的servlet映射文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>Themis</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

<servlet>
    <servlet-name>themis</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>themis</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

这是我的控制器类:

package themis;

@RestController
public class Themis {

@RequestMapping(value = "/test", method = RequestMethod.POST)
public @ResponseBody APIResponse test(@RequestBody APIRequest req) {
    System.out.println("Received request: " + req);
    APIResponse response = new APIResponse();
    response.setUser_id(req.getUser_id());
    response.setModule_id(req.getModule_id());
    response.setBot_id(req.getBot_id());
    response.setMessage(req.getIncoming_message());
    System.out.println("Sending response: " + response);
    return response;
}

@RequestMapping(value = "/test", method = RequestMethod.GET)
public @ResponseBody APIResponse testGet() {
    APIResponse response = new APIResponse();
    response.setUser_id(1);
    response.setModule_id(2);
    response.setBot_id(3);
    response.setMessage("Get works");
    System.out.println("Sending response: " + response);
    return response;
}

}

我尝试查询的网址是:

https://hidden-reef-68162.herokuapp.com/themis/test

当我使用url localhost:8080 / themis / test在本地tomcat上运行应用程序时,它完全有效。但上面的网址失败了......

部署到heroku时没有错误。

对于什么是错误的任何想法?

编辑:

以下是我在heroku中获得的日志:

2018-03-16T07:56:38.000000+00:00 app[api]: Build started by user quentin.rossettini@student.ecp.fr
2018-03-16T07:56:49.870012+00:00 app[api]: Deploy e5e3b609 by user quentin.rossettini@student.ecp.fr
2018-03-16T07:56:49.870012+00:00 app[api]: Release v10 created by user quentin.rossettini@student.ecp.fr
2018-03-16T07:56:38.000000+00:00 app[api]: Build succeeded
2018-03-16T07:56:50.369634+00:00 heroku[web.1]: Restarting
2018-03-16T07:56:50.370651+00:00 heroku[web.1]: State changed from up to starting
2018-03-16T07:56:51.258702+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-03-16T07:56:51.276442+00:00 app[web.1]: Mar 16, 2018 7:56:51 AM org.apache.coyote.AbstractProtocol pause
2018-03-16T07:56:51.276455+00:00 app[web.1]: INFO: Pausing ProtocolHandler ["http-nio-20120"]
2018-03-16T07:56:51.493167+00:00 heroku[web.1]: Process exited with status 143
2018-03-16T07:56:53.217388+00:00 heroku[web.1]: Starting process with command `java $JAVA_OPTS -jar target/dependency/webapp-runner.jar $WEBAPP_RUNNER_OPTS --port 58266 target/SpringMVC.war`
2018-03-16T07:56:54.486907+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2018-03-16T07:56:54.490474+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -Dfile.encoding=UTF-8 
2018-03-16T07:56:54.859858+00:00 app[web.1]: Expanding SpringMVC.war into /app/target/tomcat.58266/webapps/expanded
2018-03-16T07:56:54.859908+00:00 app[web.1]: Adding Context  for /app/target/tomcat.58266/webapps/expanded
2018-03-16T07:56:55.317500+00:00 heroku[web.1]: State changed from starting to up
2018-03-16T07:56:55.143050+00:00 app[web.1]: Mar 16, 2018 7:56:55 AM org.apache.coyote.AbstractProtocol init
2018-03-16T07:56:55.143064+00:00 app[web.1]: INFO: Initializing ProtocolHandler ["http-nio-58266"]
2018-03-16T07:56:55.161617+00:00 app[web.1]: Mar 16, 2018 7:56:55 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
2018-03-16T07:56:55.161620+00:00 app[web.1]: INFO: Using a shared selector for servlet write/read
2018-03-16T07:56:55.164011+00:00 app[web.1]: Mar 16, 2018 7:56:55 AM org.apache.catalina.core.StandardService startInternal
2018-03-16T07:56:55.164015+00:00 app[web.1]: INFO: Starting service [Tomcat]
2018-03-16T07:56:55.164814+00:00 app[web.1]: Mar 16, 2018 7:56:55 AM org.apache.catalina.core.StandardEngine startInternal
2018-03-16T07:56:55.164817+00:00 app[web.1]: INFO: Starting Servlet Engine: Apache Tomcat/8.5.23
2018-03-16T07:56:55.298487+00:00 app[web.1]: Mar 16, 2018 7:56:55 AM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
2018-03-16T07:56:55.298491+00:00 app[web.1]: INFO: No global web.xml found
2018-03-16T07:56:56.763293+00:00 app[web.1]: Mar 16, 2018 7:56:56 AM org.apache.jasper.servlet.TldScanner scanJars
2018-03-16T07:56:56.763329+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.
2018-03-16T07:56:56.774961+00:00 app[web.1]: Mar 16, 2018 7:56:56 AM org.apache.catalina.core.ApplicationContext log
2018-03-16T07:56:56.774963+00:00 app[web.1]: INFO: No Spring WebApplicationInitializer types detected on classpath
2018-03-16T07:56:56.818262+00:00 app[web.1]: Mar 16, 2018 7:56:56 AM org.apache.coyote.AbstractProtocol start
2018-03-16T07:56:56.818266+00:00 app[web.1]: INFO: Starting ProtocolHandler ["http-nio-58266"]

2018-03-16T07:57:45.678795+00:00 heroku[router]: at=info method=GET path="/test" host=hidden-reef-68162.herokuapp.com request_id=69dff3b3-600b-4a30-8aa5-f3259b27467f fwd="138.195.201.76" dyno=web.1 connect=0ms service=40ms status=404 bytes=1230 protocol=https
2018-03-16T07:57:48.812746+00:00 heroku[router]: at=info method=GET path="/themis/test" host=hidden-reef-68162.herokuapp.com request_id=f2b346b4-08cf-45c1-818d-064acaca6083 fwd="138.195.201.76" dyno=web.1 connect=0ms service=3ms status=404 bytes=1237 protocol=https
2018-03-16T07:57:49.157259+00:00 heroku[router]: at=info method=GET path="/themis/test" host=hidden-reef-68162.herokuapp.com request_id=c95b157e-a60b-41da-a2df-d29737d0cdd8 fwd="138.195.201.76" dyno=web.1 connect=0ms service=2ms status=404 bytes=1237 protocol=http
2018-03-16T07:57:49.380663+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=hidden-reef-68162.herokuapp.com request_id=db76ac17-349c-4b96-bb6c-96ee3466e036 fwd="138.195.201.76" dyno=web.1 connect=0ms service=3ms status=404 bytes=1237 protocol=http
2018-03-16T07:57:53.300842+00:00 heroku[router]: at=info method=GET path="/test" host=hidden-reef-68162.herokuapp.com request_id=3f9fc529-e15f-43a0-9918-6eefffd66560 fwd="138.195.201.76" dyno=web.1 connect=0ms service=2ms status=404 bytes=1230 protocol=https
2018-03-16T07:57:53.276985+00:00 heroku[router]: at=info method=GET path="/test" host=hidden-reef-68162.herokuapp.com request_id=0ac178b2-15b1-4dfc-ad58-ab96b9fa7897 fwd="138.195.201.76" dyno=web.1 connect=0ms service=3ms status=404 bytes=1230 protocol=http

0 个答案:

没有答案