使用Maven应用程序的Heroku jar部署Spring Boot,代码= H10

时间:2017-10-24 14:06:33

标签: maven spring-boot heroku jar

当我尝试访问它时,我收到了部署的代码错误H10。 我读到这是因为我必须为应用程序设置一个动态端口。 我已经尝试过在Heroku的开发中提供的所有配置,但没有幸运。

这是我的pom.xml:

public class AtLeastOnePropertyAttribute : ValidationAttribute, IClientValidatable
    {
        private readonly string[] _properties;
        public AtLeastOnePropertyAttribute(params string[] properties)
        {
            _properties = properties;
        }

        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (_properties == null || _properties.Length < 1)
            {
                return null;
            }
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value);

            List<string> props = new List<string>();
            props.Add(properties[0].ToString());
            foreach (var property in _properties)
            {

                validationContext = new ValidationContext(value);

                var propertyInfo = validationContext.ObjectType.GetProperty(property);
                if (propertyInfo == null)
                {
                    return new ValidationResult(string.Format("unknown property {0}", property));
                }

                var propertyValue = propertyInfo.GetValue(validationContext.ObjectInstance, null);
                if (propertyValue is string && !string.IsNullOrEmpty(propertyValue as string))
                {
                    return null;
                }

                if (propertyValue != null)
                {
                    return null;
                }
            }

            return new ValidationResult(FormatErrorMessage(validationContext.DisplayName), props);
        }

        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            var rule = new ModelClientValidationRule
            {
                ErrorMessage = ErrorMessage,
                ValidationType = "atleastonerequired"
            };
            rule.ValidationParameters["properties"] = string.Join(",", _properties);

            yield return rule;
        }
    }

我的主要/ resources / application.yml:

`   


<groupId>dogbook</groupId>
        <artifactId>dog-book</artifactId>
        <version>1.0</version>
        <packaging>jar</packaging>

        <name>dog-book</name>
        <description>Dog Book Backend</description>

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.4.RELEASE</version>
            <relativePath />
        </parent>

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
            <start-class>br.dogbook.Application</start-class>
            <full-artifact-name>target/${project.artifactId}-${project.version}.jar</full-artifact-name>
        </properties>

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

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

            <dependency>
                <groupId>io.jsonwebtoken</groupId>
                <artifactId>jjwt</artifactId>
                <version>0.7.0</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <optional>true</optional>
            </dependency>

            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jackson-provider</artifactId>
                <version>1.1.GA</version>
                <scope>compile</scope>
            </dependency>

        </dependencies>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>build-info</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>pl.project13.maven</groupId>
                    <artifactId>git-commit-id-plugin</artifactId>
                    <configuration>
                        <dotGitDirectory>../.git</dotGitDirectory>
                    </configuration>
                </plugin>

                <plugin>
                <groupId>com.heroku.sdk</groupId>
                <artifactId>heroku-maven-plugin</artifactId>
                <version>1.2.2</version>
                <configuration>
                    <appName>dog-book</appName>
                    <includeTarget>false</includeTarget>
                    <includes>
                        <include>${basedir}/${full-artifact-name}</include>
                    </includes>
                    <jdkVersion>1.8</jdkVersion>
                    <processTypes>
                        <web>java $JAVA_OPTS -jar ${full-artifact-name}</web>
                    </processTypes>
                </configuration>
            </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.github.jsimone</groupId>
                                        <artifactId>webapp-runner</artifactId>
                                        <version>8.5.11.3</version>
                                        <destFileName>webapp-runner.jar</destFileName>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
`

这是完整的错误:(更新)

`
server:
   port: 8080

---
  spring:
     profiles: heroku
  server:
    port: ${PORT}
`

`

我已经配置了Procfile但没有扩展名。

` 2017-10-25T04:22:38.012290+00:00 heroku[web.1]: State changed from starting to crashed 2017-10-25T09:51:04.226590+00:00 heroku[web.1]: State changed from crashed to starting 2017-10-25T09:51:06.553784+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=44562 -jar target/dog-book-1.0.jar` 2017-10-25T09:51:07.883843+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them. 2017-10-25T09:51:07.884774+00:00 app[web.1]: Error: Unable to access jarfile target/dog-book-1.0.jar 2017-10-25T09:51:07.966920+00:00 heroku[web.1]: State changed from starting to crashed 2017-10-25T09:51:07.954716+00:00 heroku[web.1]: Process exited with status 1 2017-10-25T10:50:16.461375+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dog-book.herokuapp.com request_id=945fe406-6784-4a03-8ec3-cd997da8b023 fwd="189.34.55.2" dyno= connect= service= status=503 bytes= protocol=https 2017-10-25T10:50:17.185622+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=dog-book.herokuapp.com request_id=01ce7010-cd8d-49f1-a039-f628f0e8e829 fwd="189.34.55.2" dyno= connect= service= status=503 bytes= protocol=https 2017-10-25T11:02:09.761721+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dog-book.herokuapp.com request_id=035c33ce-0340-4695-9c46-0f825bf20a24 fwd="189.34.55.2" dyno= connect= service= status=503 bytes= protocol=https 2017-10-25T11:02:10.575906+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=dog-book.herokuapp.com request_id=a52d39bb-f402-4fec-b2f4-9c6888893706 fwd="189.34.55.2" dyno= connect= service= status=503 bytes= protocol=https

还是一样。

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

错误日志未完成。访问herokuapp.com并使用您的帐户登录。您将看到完整的日志。在这里分享该日志。您还应该检查Java版本和数据库连接。大多数时候jdbc驱动程序注册是主要原因。

答案 1 :(得分:0)

与heroku默认使用的war不同,jar不会侦听Heroku检查可用性的同一端口。

请参阅https://exampledriven.wordpress.com/2016/11/04/spring-boot-heroku-example/

--server.port=$PORT添加到Procfile的诀窍对我有效。

但添加 server.port=${PORT:8080} 春天的application.properties被选中并完美运作了!