rest controller practice : scheduler

This commit is contained in:
haerong22
2021-03-22 01:09:19 +09:00
parent 6863329313
commit 67aef63aa6
7 changed files with 534 additions and 14710 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -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 {

View File

@@ -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();
}
}

View File

@@ -3,4 +3,6 @@ package com.example.restcontroller.logs.service;
public interface LogService {
void add(String text);
void deleteLog();
}

View File

@@ -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();
}
}

View File

@@ -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());