Try Hello World with the minimum configuration of Heroku Java spring-boot

Overview

Let's create an environment where Hello World can be done with the fastest / minimum configuration for launching a new Web service with Heroku + Java + spring-boot

To be able to

Approximate working time

Half an hour

What you need in advance

Heroku account is described in the following article 1. You only need to get Heroku Account in Introduction You can get it immediately for free (email address only. No credit card registration required) I tried Heroku, which can publish web applications for free

1. 1. Create spring-boot environment

There are two files to prepare, pom.xml and HelloController.java.

pom.xml


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://maven.apache.org/POM/4.0.0"
  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>sprin-boot-sample</groupId>
  <artifactId>sprin-boot-sample</artifactId>
  <version>1.0</version>
  <packaging>jar</packaging>

  <name>sprin-boot-sample</name>

  <properties>
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  </properties>

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

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

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>build-info</goal>
            </goals>
            <configuration>
              <additionalProperties>
                <encoding.source>${project.build.sourceEncoding}</encoding.source>
                <encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting>
                <java.source>${maven.compiler.source}</java.source>
                <java.target>${maven.compiler.target}</java.target>
              </additionalProperties>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

HelloController.java


package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@EnableAutoConfiguration
public class HelloController {

    @RequestMapping("/")
    @ResponseBody
    public String home() {
        return "Hello, World!";
    }

    public static void main(String[] arguments) {
        SpringApplication.run(HelloController.class, arguments);
    }

}

2. Prepare a configuration file for your Heroku environment

Three files are required.  Procfile/system.properties/application.properties

Procfile


web: java -jar target/sprin-boot-sample-1.0.jar

system.properties


java.runtime.version=1.8

application.properties


server.port=${PORT:5000}

3. 3. Prepare .gitignore so you don't upload unnecessary files to Heroku

.gitignore


target

The final composition looks like the following

{folder}
│  .gitignore
│  pom.xml
│  Procfile
│  system.properties
│      
└─src
    └─main
        ├─java
        │  └─com
        │      └─example
        │              HelloController.java
        │              
        └─resources
                application.properties

4. Commit to local git repository

git init
git add .
git commit -m "first commit"

5. Deploy to Heroku

heroku login
heroku create
git push heroku master
heroku open

6. Screen check

image.png

that's all.

Impressions

If you have a Heroku account, you can create a web service template in 30 minutes. It has only spring-boot configuration, but is it more convenient if other FWs are added to the template?

Recommended Posts

Try Hello World with the minimum configuration of Heroku Java spring-boot
Hello World with SpringBoot / Gradle
[Java] One type of alphabet prohibited With binding Hello, world! [Binding]
Hello world with Java template engine Thymeleaf
Java development with Codenvy: Hello World! Run
Try using the Wii remote with Java
Minimum configuration of Ruby REST-like API framework "grape" (with RSpec / Heroku compatible)
Try writing "Hello, World" with a combination of various languages and libraries
Java, Hello, world!
Java Hello World
Overwrite the contents of config with Spring-boot + JUnit5
Calculate the similarity score of strings with JAVA
Try the free version of Progate [Java II]
[Java] Hello World with Java 14 x Spring Boot 2.3 x JUnit 5 ~
Display "Hello World" in the browser using Java
Display "Hello World" in the browser using Java
Show a simple Hello World with SpringBoot + IntelliJ
Try to display hello world with spring + gradle
Java starting with JShell-A peek into the Java world
Try the free version of Progate [Java I]
Hello World, a cross-platform GUI app with Groovy running on the Java platform
The world of clara-rules (2)
"Hello World" in Java
CI the architecture of Java / Kotlin applications with ArchUnit
Java Learning (1)-Hello World
The world of clara-rules (4)
Monitor the internal state of Java programs with Kubernetes
Implement the UICollectionView of iOS14 with the minimum required code.
The world of clara-rules (1)
Check the behavior of Java Intrinsic Locks with bpftrace
The world of clara-rules (3)
Hello World in Java
The world of clara-rules (5)
Hello World with Micronaut
The story of making dto, dao-like with java, sqlite
Replace only part of the URL host with java
Hello World with Ruby extension library for the time being
Make a simple CRUD with SpringBoot + JPA + Thymeleaf ① ~ Hello World ~
[Java] Simplify the implementation of data history management with Reladomo
[Java] Try editing the elements of the Json string using the library
Try Hello World using plain Java on a Docker container
The story of pushing Java to Heroku using the BitBucket pipeline
Be sure to compare the result of Java compareTo with 0
Try DB connection with Java
Change the port with SpringBoot
Try gRPC with Java, Maven
Hello World with Spring Boot!
Hello World with VS Code!
java hello world, compile, run
Hello World with Spring Boot
Java beginners read Hello World
Hello, World! With Asakusa Framework!
Read the data of Shizuoka point cloud DB with Java and try to detect the tree height.
Try to imitate the idea of a two-dimensional array with a one-dimensional array
[Java1.8 +] Get the date of the next x day of the week with LocalDate
Until you run Hello World of JavaFX with VS Code + Gradle
Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy
A story about hitting the League Of Legends API with JAVA
The point of addiction when performing basic authentication with Java URLConnection
Java 10 (JDK 10) was released on March 20, 2018, so let's try Hello World.
Overwrite upload of file with the same name with BOX SDK (java)