Spring Boot
Goals
- ๋งค์ฐ ๋น ๋ฅธ ์คํ๋ง ๊ฐ๋ฐ ๊ฐ๋ฅ
- ๊ธฐ๋ณธ๋ ์ถฉ์คํ์ง๋ง, ์๊ตฌ์ฌํญ ๋ณํ์ ๋นจ๋ฆฌ ๋์
- ๋ค์ํ ๋น๊ธฐ๋ฅ ํน์ง ์ ๊ณต(์๋ฒ ๋๋ ์๋ฒ, ๋ณด์, ๋ฉํธ๋ฆญ, ํฌ์ค ์ฒดํฌ, ์ธ๋ถ ์ค์ )
Simple Example
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<!-- Additional lines to be added here... -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- (you don't need this if you are using a .RELEASE version) -->
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Executable JAR,WAR
- ๋ฆฌ๋
์ค์์ ๋จ๋
์คํ ๊ฐ๋ฅํ
*.jar
, *.war
- ์๋์ฐ๋
java -jar
ํ์
pom.xml
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.8.RELEASE</version>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
./spring-boot-jsp.jar
Spring Boot as a Service
- Executable JAR ํ์
- ์ฌ๋ณผ๋ฆญ ๋งํฌ ์ด์ฉ
sudo service myapp start
, stop
, restart
๊ฐ๋ฅ
chmod 755 /path/to/myspringboot.jar
sudo ln -s /path/to/myspringboot.jar /etc/init.d/myapp
sudo service myapp start
curl localhost:8080
sudo service myapp stop
sudo rm /etc/init.d/myapp
Migration to Spring Boot
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
related