학습68 [spring] 스프링부트의 로깅 로깅 퍼사드(Logging Facade) & 로거(Logger) Logging Facade Logger API들을 추상화해놓은 인터페이스 로깅 퍼사드를 통해 로거 사용 장점 : 구현체를 쉽게 바꿀 수 있다 (Spring Data JPA처럼) 종류 : SLF4j / JCL / Commons Logging Logger 종류: log4j2 / JUL(java.util.logging) / LogBack 스프링부트의 로깅 과거 : Commons Logging 현재 : Spring-JCL의 개입으로 Commons Logging(인터페이스) -> SLF4j(인터페이스) -> Logback(구현체) 중요 : 최종적으로 Logback을 사용함을 기억 SLF4j는 의존성에 의거하여 로거를 선택한다. 어떤 구현체로도 바꿀 .. 2020. 4. 16. [spring] 스프링의 @Configuration과 @Profile @Configuration @Bean을 통해 빈을 등록할 수 있는 자바 클래스 @Component를 포함하고 있기 때문에, Component Scan의 대상 @Profile 특정한 프로파일(환경)에서만 해당 설정이 동작 프로파일에 따라 빈 설정이 달라짐 ex) @Profile("production") + @Configuration -> 해당 프로파일에서만 해당 빈 설정 사용 @Profile("production") @Configuration public class ApplicationProductionConfig { @Bean public MyBean getMyBean(){ return new MyBean(); } } 프로파일 활성화 properties 파일 생성 X 프로퍼티 파일에 spring.prof.. 2020. 4. 15. [spring] 스프링부트의 외부 설정 (활용) 여러 프로퍼티를 묶어서 하나의 빈으로 등록하기 프로퍼티 value들을 클래스 멤버 필드로 오토 바인딩 프로퍼티 클래스에 @ConfigurationProperties("key") 선언 프로퍼티 클래스에 @Component 선언 바인딩할 프로퍼티 값들을 멤버 필드 (생략 가능) 어노테이션 프로세서 플러그인 추가 프로젝트 빌드 시 메타정보 생성 프로퍼티 파일에서 IDE의 자동완성 가이드 사용가능 by 메타정보 (생략 가능) 어플리케이션 클래스에 @EnableConfigurationProperties(프로퍼티클래스.class) 선언 스프링부트에서 자동으로 추가해주므로 생략해도 됨 //application.properties kkambi.name=kkambi kkambi.age=${random.int(0,10)}.. 2020. 4. 12. [spring] 스프링부트의 외부 설정 (개념) 스프링부트의 외부 설정 외부 설정 파일 = 어플리케이션에서 사용하는 설정 값들을 정의 application.properties 스프링 부트 실행 시 자동 로딩 key=value 형태로 정의 어플리케이션 내에서 참조 가능 @Value("${key}")로 멤버 필드에 주입 //application.properties kkambi.age=20 //ApplicationRunner public class SpringInitRunner implements ApplicationRunner { @Value("${kkambi.name}") private int age; @Override public void run(ApplicationArguments args) throws Exception { System.out.pr.. 2020. 4. 11. [spring] 스프링부트의 SpringApplication 객체 활용하기 기존 방식 SpringApplicaiton.run(Applicaiton.class, args); 스프링 커스터이징이 어려움 인스턴스를 만들어서 이용하는 방식 @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication app = new SpringApplication(Application.class); app.run(args); } } 배너 설정하기 배너 끄기 배너 클래스 구현 후 설정하기 SpringApplication app = new SpringApplicaiton(Application.class); app.setBannerMode(Banner.Mode.OFF);//.. 2020. 4. 10. 이전 1 ··· 5 6 7 8 9 10 11 ··· 14 다음