Open Pyohwan opened 4 years ago
spring-boot-devtools
는 빠르게 restart 해주는 것
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
}
fully packaged 애플리케이션에서는 자동으로 비활성화 된다. 만약
java -jar
나 혹은 특수한 classloader 로 시작한것이면 "production application" 으로 간주 된다. 그 외에는(i.e. 컨테이너에서 실행했을 경우) 직접 제외 시켜라 (-Dspring.devtools.restart.enabled=false 혹은 직접 디펜던시 제거) configuration 에서developmentOnly
하는게 다른 모듈로 전이를 방지하기 때문에 추천 함 Repackaged archives 에서는 기본적으로 devtools 은 포함 되지 않는다.
http.log-request-details
로 조절 가능
default 값을 적용하지 않으려면
spring.devtools.add-properties
를 false 로 해라
spring-boot-devtools
를 사용고 있다면, classpath 의 파일이 변경될 때 마다 자동으로 restart 된다
spring.devtools.restart.log-condition-evaluation-delta=false
spring.devtools.restart.exclude=static/**,public/**
기본값을 유지하며, 추가 exclude 하고 싶을때에는
spring.devtools.restart.additional-exclude
사용
spring.devtools.restart.additional-paths
를 사용해라spring.devtools.restart.enabled
를 사용하라spring.devtools.restart.trigger-file
src
+- main
+- resources
+- .reloadtrigger
spring.devtools.restart.trigger-file=.reloadtrigger
META-INF/spring-devtools.properties
를 직접 작성 해라spring-devtools.properties
에서 restart.exclude
와 restart.include
prefix 가 있음
include
는 "restart" classloader 로 가져와야 하는 항목exclude
는 "base" classloader 로 내려야 하는 항목restart.exclude.companycommonlibs=/mycorp-common-[\\w\\d-\.]+\.jar
restart.include.projectcommon=/mycorp-myproj-[\\w\\d-\.]+\.jar
ObjectInputStream
를 사용한 deserialized 객체는 restart 가 제대로 동작 하지 않음
ConfigurableObjectInputStream
와 Thread.currentThread().getContextClassLoader()
를 함께 써야 함spring.devtools.livereload.enabled
로 사용 여부 설정 가능
한번에 하나의 LiveReload 서버만 실행 가능하다. 애플리케이션 시작 하기 전에 다른 LiveReload 서버가 실행되는지 확인 해라
$HOME/.config/spring-boot
폴더에서 global devtools 설정 가능
spring-boot-devtools.properties
spring.devtools.remote.secret
로 강력한 암호를 넣어라.org.springframework.boot.devtools.RemoteSpringApplication
를 동일한 classpath 에서 실행해야 한다
Run Configurations…
from the Run menu.Java Application
“launch configuration”.my-app
project.org.springframework.boot.devtools.RemoteSpringApplication
as the main class.https://myapp.cfapps.io
to the Program arguments
(or whatever your remote URL is).파일은 원격 클라이언트가 실행중일때에만 모니터링하고, 만약 원격 클라이언트가 시작전에 파일이 변경 되면 서버로 push 하지 않음
FileSystemWatcher
로 특정 시간 간격으로 클래스 변경 사항을 polling.
spring.devtools.restart.poll-interval=2s
spring.devtools.restart.quiet-period=1s
spring-boot-actuator
추가를 고려해라
https://docs.spring.io/spring-boot/docs/2.2.2.RELEASE/reference/html/using-spring-boot.html#using-boot
1. Build Systems
1.1. Dependency Management
1.2. Maven
spring-boot-starter-parent
를 상속하여 기본값이 설정 됨<version>
을 안 넣어줘도 됨${…}
placeholders 는 Maven 에서@.@
placeholders 로 바꿔서 쓰면 됨1.2.1. Inheriting the Starter Parent
1.2.2. Using Spring Boot without the Parent POM
spring-boot-starter-parent
안쓰고 싶다면scope=import
넣어라1.2.3. Using the Spring Boot Maven Plugin
Gradle
Ant
build.xml
1.5. Starters
2. Structuring Your Code
2.1. Using the “default” Package
Application.java
은@SpringBootApplication
과 함께 main 메소드를 선언 함import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication public class Application {
}
import org.springframework.boot.autoconfigure.; import org.springframework.boot.autoconfigure.jdbc.; import org.springframework.context.annotation.*;
@Configuration(proxyBeanMethods = false) @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) public class MyConfiguration { }
package com.example.service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;
@Service public class DatabaseAccountService implements AccountService {
}
@Service public class DatabaseAccountService implements AccountService {
}
package com.example.myapplication;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan public class Application {
}
$ java -jar target/myapplication-0.0.1-SNAPSHOT.jar
$ java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \ -jar target/myapplication-0.0.1-SNAPSHOT.jar
$ mvn spring-boot:run
$ export MAVEN_OPTS=-Xmx1024m
$ gradle bootRun
$ export JAVA_OPTS=-Xmx1024m