Erstellen Sie eine Umgebung, in der Hello World mit der schnellsten / minimalsten Konfiguration zum Starten eines neuen Webdienstes mit Heroku + Java + Spring-Boot ausgeführt werden kann
Ein halbe Stunde
Das Heroku-Konto wird im folgenden Artikel 1 beschrieben. Holen Sie sich einfach das Heroku-Konto in Einführung OK Sie können es sofort kostenlos erhalten (nur E-Mail-Adresse. Keine Creca-Registrierung erforderlich) Ich habe Heroku ausprobiert, das Webanwendungen kostenlos veröffentlichen kann
Es müssen zwei Dateien vorbereitet werden: pom.xml und 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);
}
}
Es sind drei Dateien erforderlich. 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
Die endgültige Komposition sieht wie folgt aus
{Ordner}
│ .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
das ist alles.
Wenn Sie ein Heroku-Konto haben, können Sie in 30 Minuten eine Webdienstvorlage erstellen. Die Konfiguration ist nur Spring-Boot, aber ist es bequemer, wenn der Vorlage andere FWs hinzugefügt werden?
Recommended Posts