티스토리 뷰
728x90
반응형
환경
- spring boot 2.7.10
스프링 배치에서 특정 Job만 실행하고 싶을 때 여러 블로그에서 봤을 때는 properties 파일이나 yaml 파일에
아래와 같은 속성을 넣고
spring.batch.job.names=${job.name:NONE}
실행 시 Program Argument에 아래와 같이 실행
--job.name=특정잡이름
이렇게 하라고 하는데 잘 안된다.. 버전이 바뀌고 나서 안되는 건지는 잘 모르겠는데 구글링 하다가 찾은 방법으로 된다.
해결
Program Argument에 아래와 같이 작성
--spring.batch.job.names=특정 잡이름
추가로 여기서 job의 이름은 job1234 이다.
나는 잡의 이름이 Bean이 생성될 때의 이름인줄 알고 계속 job1을 argument로 넣었는데 실행이 안되어서 job1234로 넣었더니 실행이 되었다..
@Bean
public Job job1() {
return jobBuilderFactory.get("job1234")
.incrementer(new RunIdIncrementer())
.start(..)
.build();
}
삽질하다가 JobBuilderFactory 클래스를 타고 들어가서 get() 메소드를 살펴보니 친절히 써져있구나 ㅎㅎ
public class JobBuilderFactory {
private JobRepository jobRepository;
public JobBuilderFactory(JobRepository jobRepository) {
this.jobRepository = jobRepository;
}
/**
* Creates a job builder and initializes its job repository. Note that if the builder is used to create a @Bean
* definition then the name of the job and the bean name might be different.
*
* @param name the name of the job
* @return a job builder
*/
public JobBuilder get(String name) {
JobBuilder builder = new JobBuilder(name).repository(jobRepository);
return builder;
}
친절히 parameter의 name은 잡의 이름이라고 나와있따 ㅎㅎ
728x90
반응형
댓글
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- jQuery
- 오라클
- 베리 심플
- localtime
- maven
- Java
- Spring
- intellij
- LocalDate
- JavaScript
- elasticsearch
- mybatis config
- k8s
- window
- Mac
- input
- claude
- Linux
- Spring Security
- docker
- config-location
- Bash tab
- rocky
- LocalDateTime
- 북리뷰
- springboot
- mybatis
- oracle
- Kotlin
- svn
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함
반응형