본문 바로가기

Spring5

spring @Conditional 사용하기 Spring @Conditional 활용하기 Spring 설정중 특정 조건에 따라 적용 하고 싶을 때 활용할 수 있는 애노테이션이 있다. @Configuration class, @Bean method 등에 활용할 조건에 따라 적용 할 수 있다. Condition class @Conditional 애노테이션을 적용하기 위해서는 Condition 클래스를 포함해야 한다. Condition 클래스는 애노테이션 선언시 적용 할 것인지 안 할 것인지 판단해 주는 클래스이다. matches(context: ConditionContext, metadata: AnnotatedTypeMetadata): Boolean 메서드를 오버라이드 하여 적용 여부를 판단해 반환해 주면 된다. class MyCondition : Co.. 2023. 3. 12.
Bean의 생성과 소멸에 발생되는 이벤트 Bean 이 생성된 직후 그리고 소멸직전 이벤트가 발생하여 해당 이벤트에 내가 원하는 동작을 넣을 수 있다. @PostConstruct: call after construct @PreDestroy: call before destroy @PostConstruct public void init() { System.out.println("hello."); } @PreDestroy public void destroy() { System.out.println("bye."); } 가끔이지만 아주 유용하게 사용되는 기능이니 잘 기억해 두는 것이 좋겠다. 2020. 2. 13.
데이터 변경 알림 - @EntityListeners spring 의 data-jpa 사용시 데이터 변경시 알림을 받는 방법이 있다. EntityListener 클래스를 만들고 public class DataDtoListener { @PostLoad public void postLoad(DataDto dto) { log.info("post load: {}", dto); } @PrePersist public void prePersist(DataDto dto) { log.info("pre persist: {}", dto); } @PostPersist public void postPersist(DataDto dto) { log.info("post persist: {}", dto); } @PreUpdate public void preUpdate(DataDto dt.. 2020. 2. 11.
Spring + StompWebsocket Maven dependences org.springframework.boot spring-boot-starter-websocket org.webjars sockjs-client 1.1.2 org.webjars stomp-websocket 2.3.3-1 HTML Java config @Configuration @EnableWebSocketMessageBroker public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { @Override public void configureMessageBroker(MessageBrokerRegistry config) { config.enableSimpleBroker("/events”); // se.. 2020. 2. 1.
Cron 정리 Attribute Description cron Cron Expression을 이용하여 Task 실행 주기 정의. Cron Expression은 6개의 Field로 구성되며 각 Field는 순서대로 second, minute, hour, day, month, weekday를 의미한다. 각 Field의 구분은 Space로 한다. 또한 month와 weekday는 영어로 된 단어의 처음 3개의 문자로 정의할 수 있다. 0 0 * * * * : 매일 매시 시작 시점 */10 * * * * * : 10초 간격 0 0 8-10 * * * : 매일 8,9,10시 0 0/30 8-10 * * * : 매일 8:00, 8:30, 9:00, 9:30, 10:00 0 0 9-17 * * MON-FRI : 주중 9시부터 17.. 2020. 2. 1.