@Scheduled을 이용해 일정 시간 마다 코드 실행
@Scheduled을 사용하기 위해 ApplicationClass에 @EnableScheduling을 추가해야함
@EnableScheduling
@SpringBootApplication
public class Chatting01Application { }
@Component(@Service 등) 즉, 스프링 빈에 등록된 클래스의 메소드에 @Scheduled를 걸어줌
, 이때 메소드는 매개변수x 이고 반환타입은 void
@Service
public class SseService {
@Scheduled(fixedDelay = 1000) // 1초마다 실행
public void sendEvents() { }
}
'Spring > 기타 여러가지' 카테고리의 다른 글
| DTO에 어떤 어노테이션 붙여야 할까 (0) | 2025.04.14 |
|---|---|
| 읽어볼 주제들 (0) | 2025.02.08 |
| ServletContainer 01 (0) | 2025.02.01 |
| Spring WebSocket 01 (1) | 2025.02.01 |
| STOMP (1) | 2025.01.30 |