Reputation: 1
I have a Gradle-Kotlin project that is a Spring boot project, and it runs a server on port 8080 by default.
When I compile and generate a jar with command ./gradlew bootJar, I can set up the server justing by executing this jar. I wanted to run this server remotely, so I used Heroku (heroku deploy:jar) to upload the .jar. I could upload the jar and start the server with Heroku and it detected the buildback as heroku/jvm. With command heroku logs --tail
I could verify that the server compiled and was up and running... but on port 8080. That is, I could't reach the server using heroku's public app url (ex https://radiant-crag-94685.herokuapp.com/my-end-point)
Reading some docs, I came to the PORT configuration. So I created a file called application.yml and put it in src/main/resources folder. This .yml file contained the following:
server:
port: $PORT
I generated the .jar file and uploaded to Heroku once more. But this time, the app crashed on its main class, with the message:
Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Integer] for value '$PORT'; nested exception is java.lang.NumberFormatException: For input string: "$PORT"
The exception was thrown here:
@SpringBootApplication
open class AutomatedTestsApplication
fun main(args: Array<String>) {
runApplication<AutomatedTestsApplication>(*args)
}
How can I solve this problem?
Upvotes: 0
Views: 343
Reputation: 1
You can use the variable in your application.yml like you have doing this:
server:
port: ${PORT}
Alternatively, as you mentioned in your comment, I think it would be better to override via startup command using something like:
java -jar service.jar --server.port=${PORT}
Upvotes: 0