在Heroku上部署Spring Boot项目时出现问题

时间:2016-12-30 06:06:13

标签: java spring heroku spring-boot

我在Heroku上部署Spring Boot项目时遇到问题。日志告诉我这个:

2016-12-30T05:32:00.486410+00:00 heroku[slug-compiler]: Slug compilation started
2016-12-30T05:32:00.486416+00:00 heroku[slug-compiler]: Slug compilation finished
2016-12-30T05:32:00.460515+00:00 heroku[web.1]: State changed from down to starting
2016-12-30T05:32:04.118436+00:00 heroku[web.1]: Starting process with command `java $JAVA_OPTS -jar webapp-runner.jar ${WEBAPP_RUNNER_OPTS} --port 50393 ./target/ziaevtestapp-1.0-SNAPSHOT.war`
2016-12-30T05:32:06.189153+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2016-12-30T05:32:06.192420+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx350m -Xss512k -Dfile.encoding=UTF-8
2016-12-30T05:32:06.801027+00:00 app[web.1]: Expanding ziaevtestapp-1.0-SNAPSHOT.war into /app/target/tomcat.50393/webapps/expanded
2016-12-30T05:32:06.801130+00:00 app[web.1]: Adding Context  for /app/target/tomcat.50393/webapps/expanded
2016-12-30T05:32:07.915956+00:00 app[web.1]: Dec 30, 2016 5:32:07 AM org.apache.coyote.AbstractProtocol init
2016-12-30T05:32:07.915983+00:00 app[web.1]: INFO: Initializing ProtocolHandler ["http-nio-50393"]
2016-12-30T05:32:07.936445+00:00 app[web.1]: Dec 30, 2016 5:32:07 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
2016-12-30T05:32:07.936448+00:00 app[web.1]: INFO: Using a shared selector for servlet write/read
2016-12-30T05:32:07.942963+00:00 app[web.1]: Dec 30, 2016 5:32:07 AM org.apache.catalina.core.StandardService startInternal
2016-12-30T05:32:07.942966+00:00 app[web.1]: INFO: Starting service Tomcat
2016-12-30T05:32:07.948857+00:00 app[web.1]: Dec 30, 2016 5:32:07 AM org.apache.catalina.core.StandardEngine startInternal
2016-12-30T05:32:07.948860+00:00 app[web.1]: INFO: Starting Servlet Engine: Apache Tomcat/8.0.33
2016-12-30T05:32:08.417576+00:00 heroku[web.1]: State changed from starting to up
2016-12-30T05:32:08.536162+00:00 app[web.1]: Dec 30, 2016 5:32:08 AM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
2016-12-30T05:32:08.536196+00:00 app[web.1]: INFO: No global web.xml found
2016-12-30T05:32:15.390786+00:00 app[web.1]: Dec 30, 2016 5:32:15 AM org.apache.jasper.servlet.TldScanner scanJars
2016-12-30T05:32:15.425370+00:00 app[web.1]: Dec 30, 2016 5:32:15 AM org.apache.catalina.core.ApplicationContext log
2016-12-30T05:32:15.390817+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.
2016-12-30T05:32:15.425374+00:00 app[web.1]: INFO: 1 Spring WebApplicationInitializers detected on classpath
2016-12-30T05:32:15.479544+00:00 app[web.1]: Dec 30, 2016 5:32:15 AM org.apache.coyote.AbstractProtocol start
2016-12-30T05:32:15.479547+00:00 app[web.1]: INFO: Starting ProtocolHandler ["http-nio-50393"]

的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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ru.inovus.ziaevtestapp</groupId>
    <artifactId>ziaevtestapp</artifactId>
    <packaging>war</packaging>
    <!--<packaging>jar</packaging>-->
    <version>1.0-SNAPSHOT</version>
    <name>ziaevtestapp</name>
    <url>http://maven.apache.org</url>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.RELEASE</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
        <start-class>ru.inovus.ziaevtestapp.Application</start-class>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.10</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals><goal>copy-dependencies</goal></goals>
                        <configuration>
                            <artifactItems>
                                <groupId>com.hithub.jsimone</groupId>
                                <version>8.0.24.0</version>
                                <destFileName>webapp-runner</destFileName>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestone</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>

        <repository>
            <id>sonatype-snapshot</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestone</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>

        <pluginRepository>
            <id>jetty</id>
            <url>http://mvnrepository.com/artifact/org.eclipse.jetty</url>
        </pluginRepository>
    </pluginRepositories>
</project>

Procfile

web: java -jar target/*.war

当我转到我的应用页面https://ziaevtestapp.herokuapp.com/

时,应用程序无法启动

我只看到“应用程序错误”,有人知道我做错了吗?

1 个答案:

答案 0 :(得分:0)

日志建议您使用heroku deploy:warmvn heroku:deploy-war部署WAR文件,该文件为您提供Tomcat容器。但是使用Spring Boot,你会希望你的Procfile直接执行WAR文件。为此,请使用heroku deploy:jarmvn heroku:deploy