伙伴,我尝试使用本教程将springboot应用程序部署到heroku:
https://www.youtube.com/watch?v=7RHYDNSRSOs&t=324s
所以我一步一步地完成了所有工作(除了他使用了maven,但是我使用了gradle,但我认为这并不重要),但是它永远都无法工作。 所以这是我的源代码:
https://github.com/AzamatIbraimov/herokuheroker
这是属性:
spring.datasource.url=${JDBC_DATABASE_URL}
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}
spring.jpa.show-sql=false
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
Gradle版本:
buildscript {
ext {
kotlinVersion = '1.2.51'
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-noarg:${kotlinVersion}")
// add docker dependency
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.3.RELEASE")
// using Gradle you need to add a new docker plugin like this:
classpath('se.transmode.gradle:gradle-docker:1.2')
}
}
apply plugin: 'kotlin-jpa'
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
// apply this docker plugin
apply plugin: 'docker'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
compileKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile 'mysql:mysql-connector-java'
compile('org.springframework.boot:spring-boot-starter-data-rest')
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
compile group: 'postgresql', name: 'postgresql', version: '9.0-801.jdbc4'
compile('org.springframework.boot:spring-boot-starter-web')
compile('com.fasterxml.jackson.module:jackson-module-kotlin')
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
compile("org.jetbrains.kotlin:kotlin-reflect")
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
// write this docker build task, this will run just after "./gradlew build" command
task buildDocker(type: Docker, dependsOn: build) {
push = true
applicationName = bootJar.baseName
dockerfile = file('Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
Heroku日志:
2019-07-21T17:11:17.000000+00:00 app[api]: Build succeeded
2019-07-21T17:11:27.578719+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=herokuheroker.herokuapp.com request_id=37c76a90-7399-4e0e-9618-61064cf46804 fwd="94.143.197.11" dyno= connect= service= status=503 bytes= protocol=https
2019-07-21T17:11:28.204564+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=herokuheroker.herokuapp.com request_id=8bfda982-3c34-4990-a1cf-8a458b6e7e8b fwd="94.143.197.11" dyno= connect= service= status=503 bytes= protocol=https
2019-07-21T17:15:41.211595+00:00 heroku[web.1]: State changed from crashed to starting
2019-07-21T17:15:45.265625+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=58253 $JAVA_OPTS -jar build/libs/*.jar`
2019-07-21T17:15:46.788409+00:00 heroku[web.1]: State changed from starting to crashed
2019-07-21T17:15:46.702134+00:00 app[web.1]: Create a Procfile to customize the command used to run this process: https://devcenter.heroku.com/articles/procfile
2019-07-21T17:15:46.726892+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2019-07-21T17:15:46.728390+00:00 app[web.1]: Error: Unable to access jarfile build/libs/*.jar
2019-07-21T17:15:46.768981+00:00 heroku[web.1]: Process exited with status 1
2019-07-21T17:16:46.689916+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=herokuheroker.herokuapp.com request_id=b83fc9f5-1fb8-4b79-94c9-0b8339bf2712 fwd="94.143.197.11" dyno= connect= service= status=503 bytes= protocol=https
2019-07-21T17:16:47.240071+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=herokuheroker.herokuapp.com request_id=892f722a-046f-4532-b1d1-c02dda98ee24 fwd="94.143.197.11" dyno= connect= service= status=503 bytes= protocol=https