기본 콘텐츠로 건너뛰기

3월, 2018의 게시물 표시

스프링부트, Externalized Configuration

환경변수 설정 설정파일을 어플리케이션 밖에서 관리함으로써 같은 어플리케이션으로 여러가지 설정을 변경하면서 운영할 수 있다. Properties files, yaml files, environment variable, command-line arguments 사용 @Value 어노테이션을 통해 주입받을 수 있다. 우선순위 스프링부트에서는 환경변수값을 읽는 우선순위가 있다. 만약 예사외의 값이 적용되었다면 아래 순위를 확인해보자 devtools -> test관련 -> command line -> servlet -> Jndi -> system property -> environments -> random -> properties file -> @Configuration classes 1. [Devtools global settings properties](https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-devtools-globalsettings) on your home directory (~/.spring-boot-devtools.properties when devtools is active). 2. [@TestPropertySource](https://docs.spring.io/spring/docs/5.0.5.BUILD-SNAPSHOT/javadoc-api/org/springframework/test/context/TestPropertySource.html) annotations on your tests. 3. [@SpringBootTest#properties](https://docs.spring.io/spring-boot/docs/2.0.1.BUILD-SNAPSHOT/api/org/springframework/boot/test/context/Spr

스프링부트, SpringApplication 클래스

springApplication SpringApplication 스프링 어플리케이션을 간편하게 실행할 수 있도록 제공하는 클래스 main()함수를 통해 실행되며, 기본 로그 수준은 info 이다. The following example shows potential logging settings in application.properties: logging.level.root=WARN logging.level.org.springframework.web=DEBUG logging.level.org.hibernate=ERROR FailureAnalyzers 스프링 실행시 오류가 발생하면 에러메세지와 해결 방법을 제시해준다. \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* APPLICATION FAILED TO START \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Description: Embedded servlet container failed to start. Port 8080 was already i n use. Action Identify and stop the process that's listening on port 8080 or configure this application to listen on another port. customizing the Banner 스프링 실행시에 로딩되는 배너를 수정할 수 있다. classpath에 존재하는 banner.txt를 수정 (spring.banner.location) 텍스트 파일 대신에 이미지도 가능하다 (spring.banner.image.location) 스프링 부트 생성기 https://devops.datenkollektiv.de/banner.txt/index.html SpringA

스프링부트, spring-boot-devtools

스프링부트에서 소스코드 수정시 자동으로 서버를 재시작 하는 기능등을 제공한다. maven dependencies < dependencies > < dependency > < groupid > org.springframework.boot </ groupid > < artifactid > spring-boot-devtools </ artifactid > < optional > true </ optional > </ dependency > </ dependencies > 자동 restart classpath가 변경되면 어플리케이션이 자동으로 restart ide마다 차이가 좀 있는데 eclipse는 저장시에 classpath 변경이 발생하지만, intellij는 build project 기능을 통해 진행된다. Restart vs Reload spring boot는 2개의 classloader를 사용 Base classloader : 변하지 않는 3rd party용 .jar파일같은 Restart classloader : 개발자가 직접 작성하는 클래스 같은 Restart 실행시에 base classloader가 미리 작업한 부분은 할필요하고 없으므로 효율적임 만약 restart 가 충분히 빠르지 못하게 작동한다면 JRebel의 reloading을 고려 Excluding Resources /META-INF/maven, /META-INF/resources, /resources, /static, /public, or /templates 이곳 폴더들은 변경이 일어나도 restart가 발생하지 않음 spring.devtools.restart.exclude= static /**,public/** 이런식으로 추가로 설정가능 Watching

elasticsearch cors문제

~/config/elasticsearch.yml 파일 열고 아래 추가 http.cors.enabled : true http.cors.allow-origin: "*" http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE http.cors.allow-headers : "X-Requested-With,X-Auth-Token,Content-Type, Content-Length, Authorization"