기본 콘텐츠로 건너뛰기

스프링부트, 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
  • SpringApplication.setBanner(… ) 함수를 통해 배너를 커스터마이징 할 수 도 있다.

SpringApplication 수행순서

  1. ApplicationContext 인스턴스 생성
  2. CommandLinePropertySource를 spring properties에 등록
  3. Application context를 새로고침하고, 모든 싱글톤 bean을 로딩
  4. CommandLineRunner bean을 트리거
    ** 모든 bean은 ApplicationContext에서 관리

Application Events and Listeners

  • 어떤 이벤트들은 ApplicationContext가 생성되기전에 trigger된다. 이런경우에 listner들은 @Bean으로 등록할 수가 없다. 그래서 SpringApplication.addListeners(… ), SpringApplicationBuilder.listeners(… ) 을 통해 등록이 가능하다.
  • 만약 자동으로 하고 싶으면 META-INF/spring.factories 에 등록한다.
  org.springframework.context.ApplicationListener=com.example.project.MyListener
이벤트
  1. ApplicationStartingEvent : 리스너 등록 및 초기화, 모든 프로세스 시작 이전
  2. ApplicationEnvironmentPreparedEvent : Enviroment 객체가 context에 사용될때, context가 생성되기 이전
  3. ApplicationPreparedEvent : bean정의가 load되고 refresh 되기전
  4. ApplicationStartedEvent : context가 refresh되고, command-line runner가 호출되기전에
  5. ApplicationReadyEvent : command-line runner가 호출되고, service request를 요청받을 준비 알림
  6. ApplicationFailedEvent : exception이 발생했을때

Web Environment

  • 스프링 mvc, 스프링 web flux일때 AnnotationConfigServletWebServerApplicationContext,
  • 아닐때 AnnotationConfigApplicationContext
  • 강제로 ApplicationContext를 지정할 수도 있다. (setApplicationContextClass(), setWebApplicationType() 함수 사용)

Accessing Application Arguments

SpringApplication.run(… ) 함수의 Arguments에 접근하고 싶다면 org.springframework.boot.ApplicationArguments bean을 주입받으면 된다.

Using the ApplicationRunner or CommandLineRunner

springApplication실행할때 ApplicationRunner 또는 CommandLineRunner 인터페이스를 활용할 수 있다. 둘다 run()에 의해 실행된다.
참고

댓글

이 블로그의 인기 게시물

메일서버가 스팸으로 취급받을때

설치한 메일서버를 통해 발송되는 메일이 스팸으로 들어가는 경우가 더러 있다. 이게 한번 들어가기는 쉬운데, 빠져나오기는 드럽게 힘든것 같다... 본인의 경우에는 우선 국내서비스에는 별 무리 없이 들어간다. (naver,daum 등) 그런데 해외메일 그중 Gmail, Hotmail 에는 에누리없이 스팸으로 간주되고 있었다. Gmail같은 경우에는 그래도 스팸함으로 발송은 제대로 되는반면에 Hotmail같은경우에는 아예 수신자체가 안되는 경우도 더러있다.. ㅡ,.ㅡ; 제일 좋은 방법은 Gmail,Hotmail에 전화걸어서 우리 메일서버 IP white Ip로 등록해달라!!! 하면 좋지만, 얘네들은 걸어봤자 자동응답기고, 문의채널은 구글 그룹스 게시판이 전부다.. 본론으로 들어가서. 해외 메일이 차단될 경우 내 매일서버ip가 스팸ip로 등록되 버린 경우일 수 있다. (본인처럼. ㅎ) 이것부터 조회 해보고 싶으면 RBL(real-time blocking List) 체크를 해야 하는데, RBL체크 해주는 사이트는 꽤 많이 있고, 그중 좀 깔끔해 보이는곳 하나 소개. http://www.anti-abuse.org/ 메일서버ip 입력하고 조회해보면 쭈루룩 리스트가 나온다. 그 중 빨간불이 들어온 부분이 메일 서버가 스팸서버가 된 각종 이유들이다.ㅋ 본인의 경우 CBL 때문에 걸렸는데, 내용은 아래와 같다. This IP address is HELO'ing as  "localhost.localdomain"  which violates the relevant standards (specifically: RFC5321). 메일서버 도메인에 별다른 작업을 안해놓아서 "localhost.localdomain" 으로 설정되어있었다. 만약 CBL만 바로 테스트 해보고 싶으면 http://cbl.abusea

[javascript] 특정시간에만 함수 실행

특정시간에만 팝업을 띄우려면?? 특정시간에만 로그인을 막으려면?? 특정시간에만 할일은 의외로 참 많다. 방법? 딱히 없다. 현재시간 구해서 시작시간, 종료시간 사이에 있을때 시작하는 수밖엔. if ((현재시간 > 시작시간) && (현재시간 < 종료시간)){ .. 팝업노출(); 공사페이지 리다이렉트(); 기타등등(); .. } 자바스크립트로 작성하면 다음과 같다. var startdate = "2014012008" ; var enddate = "2014012418" ; var now = new Date (); //현재시간 year = now. getFullYear (); //현재시간 중 4자리 연도 month = now. getMonth () + 1 ; //현재시간 중 달. 달은 0부터 시작하기 때문에 +1 if ((month + "" ). length < 2 ){ month = "0" + month; //달의 숫자가 1자리면 앞에 0을 붙임. } date = now. getDate (); //현재 시간 중 날짜. if ((date + "" ). length < 2 ){ date = "0" + date; } hour = now. getHours (); //현재 시간 중 시간. if ((hour + "" ). length < 2 ){ hour = "0" + hour; } today = year + "" + month + "" + date + "" + hour; //오늘 날짜 완성. / / 시간비교 i

[linux] 모든 cron 확인

예전에 만들어놓은 cron이 요새 안돌고 있어서 찾아봤다. 물론 내가 만들었던 아니고ㅋ crontab -l no crontab for root 헐, 내가 찾던 cron이 안보인다. 분명히 예전 사수가 여기다 작업 해놓은것 같았는데... cron이 뭐하는 놈인지는 알아도, 어떻게 생겨먹은놈인지는 몰랐다ㅋ 이리저리 폴더 뒤져서 그때 스크립트 파일을 찾아보기 시작했다. 멍청한짓을 한 참 한후에 혹하는 마음에 로컬 사용자 뭐있나 찍어봄 cat /etc/passwd 찍어보믄 계정별로 결과가 쭈루루룩 나오는데, 뜻은 이거다. 계정:암호:UID:GID:정보:디렉토리:쉘 passwd 파일 설명은 ( http://www.linuweb.com/?p=248 ) 여기 님 블로그에 잘 되어있음. 암튼 결국 계정별로 cron 걸려있는거 죄다 찍어보니 for user in $(cut -f1 -d: /etc/passwd); do echo id $user; crontab -u $user -l ; done 한번에 다찍어주는 명령어는 따로 없나보다. 간단하게 스크립트로 찍어주는 수밖에. 결국 내가 찾던 cron은 처음보는 계정에 들어있었음. 그리고 cron이 안돌던 이유는 ftp가 막혀서였고 ㅋ