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
Half an hour
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
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);
}
}
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}
.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
git init
git add .
git commit -m "first commit"
heroku login
heroku create
git push heroku master
heroku open
that's all.
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