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 | 31 |
Tags
- html/css 완강
- 손목난민
- 컨테이너 지우기
- sne573
- pbcopy
- python scrap
- 야근
- js이론
- 클론코딩
- eventsourcing
- Docker
- 전체지우기
- 시계 줄질
- 가성비 다이버
- python scrap title
- 떱텐
- 5600B
- github
- html/css
- mn나토
- 재택
- 주우재시계
- 1일1커밋
- CSS
- 코더가 아닌 개발자
- python flask
- 리팩터링
- Git
- python
- 다짐
Archives
- Today
- Total
발전하는 나를 기록하기 위해
스프링 부트 구동 시점에 특정 코드 실행 시키기 (CommandLineRunner & ApplicationRunner) 본문
728x90
첫번째
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.Arrays;
@Component
public class DemoCommandLineRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("CommandLineRunner Args: " + Arrays.toString(args));
}
}
두번째
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.util.Arrays;
@Component
public class DemoApplicationRunner implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("ApplicationRunner Args: " + Arrays.toString(args.getSourceArgs()));
}
}
세번째(빈과 람다 사용해서 한번에)
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class ExceptionhandlerExampleApplication {
public static void main(String[] args) {
SpringApplication.run(ExceptionhandlerExampleApplication.class, args);
}
@Bean
public ApplicationRunner applicationRunner() {
return args -> { // 코드 작성
};
}
}
'개발 > Spring' 카테고리의 다른 글
logback-spring 설정 (0) | 2024.03.28 |
---|---|
트랜잭션 매니저와 트랜잭션 동기화 매니저 (0) | 2024.03.13 |