반응형
250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Airflow
- java bigdecimal
- COALESCE
- node
- Spring
- codebuild
- kubeflow
- aws
- docker
- Flux
- VPN
- chartjs
- bootstrap
- Spring Error
- chart.js
- PostgreSQL
- 도커
- codedeploy
- IntelliJ
- aws cicd
- AWS CI/CD 구축하기
- Jenkins
- redis
- codepipeline
- or some instances in your deployment group are experiencing problems.
- Python
- JavaScript
- SQL
- codedeploy error
- Kafka
Archives
- Today
- Total
Small Asteroid Blog
[Spring] 스케쥴러 사용해 일정주기마다 코드 실행하기 본문
728x90
스케쥴러를 사용해 일정 주기마다 코드를 실행시키고자 한다
servlet-context.xml 에서 아래 두 줄을 추가한다.
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation= "http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd"
xsi:schemaLocation 의 경우 이미 적혀 있는 곳에서 http만 추가해주면된다.
결과
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd"
>
servlet-context.xml 하단에 다음 코드도 추가한다.
패키지 이름은 사용하고자 하는 스케줄러가 있는 위치의 패키지를 작성한다.
<!-- 스케쥴러파일이 존재하는 패키지 설정 -->
<context:component-scan base-package="패키지 이름" />
<!-- 해당 태그들은 크론탭을 설정에 필요한 태그들 -->
<task:scheduler id="jobScheduler" pool-size="10" />
<task:annotation-driven scheduler="jobScheduler" />
자바에서
초 분 시 일 월 요일
순으로 작성하면된다.
시간은 24시
*는 전체
//초 분 시 일 월 요일
@Scheduled(cron="0 * 16 * * *")
public void scheTest1() {
System.out.println("test1");
}
728x90
반응형
'백엔드 > Spring' 카테고리의 다른 글
ORA-00942: 테이블 또는 뷰가 존재하지 않습니다 (0) | 2020.11.29 |
---|---|
spring 에서 오라클 연결하기 (0) | 2020.11.27 |
[Tomcat 에러] Several ports (8005, 8080, 8009) required by Tomcat v9.0 Server at localhost are already in use. (0) | 2020.06.11 |
STS 에서 메이븐 프로젝트 생성하자 마자 pom.xml 에러 생기는 경우 (0) | 2020.05.21 |
RESTFul (0) | 2020.05.20 |