# Spring Boot
- https://github.com/spring-projects/spring-boot
## Goals
- 매우 빠른 스프링 개발 가능
- 기본도 충실하지만, 요구사항 변화에 빨리 대응
- 다양한 비기능 특징 제공(임베디드 서버, 보안, 메트릭, 헬스 체크, 외부 설정)
## Simple Example
- https://start.spring.io
- spring boot 기본 앱 생성
- Example.java
```java
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);
}
}
```
- pom.xml
```xml
4.0.0
com.example
myproject
0.0.1-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
2.0.0.BUILD-SNAPSHOT
org.springframework.boot
spring-boot-starter-web
spring-snapshots
http://repo.spring.io/snapshot
true
spring-milestones
http://repo.spring.io/milestone
spring-snapshots
http://repo.spring.io/snapshot
spring-milestones
http://repo.spring.io/milestone
org.springframework.boot
spring-boot-maven-plugin
```
## Executable JAR,WAR
- 리눅스에서 단독 실행 가능한 `*.jar`, `*.war`
- 윈도우는 `java -jar` 필요
- `pom.xml`
```xml
org.springframework.boot
spring-boot-maven-plugin
1.5.8.RELEASE
true
```
- 실행
```
./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
```
- run
```
sudo service myapp start
curl localhost:8080
```
- stop
```
sudo service myapp stop
sudo rm /etc/init.d/myapp
```
- ref : https://stackoverflow.com/questions/21503883/spring-boot-application-as-a-service
## Migration to Spring Boot
- http://www.baeldung.com/spring-boot-migration
- pom.xml
```
org.springframework.boot
spring-boot-starter-parent
1.5.6.RELEASE
```
## related
- [Spring Boot 2](/mib/spring/boot2)