rest controller practice : scheduler
This commit is contained in:
@@ -3,7 +3,9 @@ package com.example.restcontroller;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@EnableScheduling
|
||||
@EnableAspectJAutoProxy
|
||||
@SpringBootApplication
|
||||
public class RestControllerApplication {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.example.restcontroller.common.schedule;
|
||||
|
||||
import com.example.restcontroller.logs.service.LogService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class Scheduler {
|
||||
|
||||
private final LogService logService;
|
||||
|
||||
// @Scheduled(cron = "0 0 4 * * *")
|
||||
// @Scheduled(fixedDelay = 1000 * 60)
|
||||
public void deleteLog() {
|
||||
log.info("################################");
|
||||
log.info("스케줄 실행!!!!");
|
||||
log.info("################################");
|
||||
|
||||
logService.deleteLog();
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,6 @@ package com.example.restcontroller.logs.service;
|
||||
public interface LogService {
|
||||
|
||||
void add(String text);
|
||||
|
||||
void deleteLog();
|
||||
}
|
||||
|
||||
@@ -3,10 +3,14 @@ package com.example.restcontroller.logs.service;
|
||||
import com.example.restcontroller.logs.entity.Logs;
|
||||
import com.example.restcontroller.logs.repository.LogsRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LogServiceImpl implements LogService{
|
||||
@@ -21,4 +25,10 @@ public class LogServiceImpl implements LogService{
|
||||
.regDate(LocalDateTime.now())
|
||||
.build());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void deleteLog() {
|
||||
logsRepository.deleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,4 +74,10 @@ VALUES
|
||||
'<div><p>제목: {BOARD_TITLE}</p><p>내용</p><div>{BOARD_CONTENTS}</div><p>답변</p><div>{BOARD_REPLY_CONTENTS}</div></div>',
|
||||
'test.email.12588@gmail.com', '관리자', now());
|
||||
|
||||
|
||||
insert into logs (text, reg_date)
|
||||
values
|
||||
('로그1', now()),
|
||||
('로그2', now()),
|
||||
('로그3', now()),
|
||||
('로그4', now()),
|
||||
('로그5', now());
|
||||
|
||||
Reference in New Issue
Block a user