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
- insertion sort
- 혼자 공부하는 C언어
- buffer
- JSON
- datastructure
- list 컬렉션
- 알기쉬운 알고리즘
- Serialization
- Selection Sorting
- coding test
- Graph
- 윤성우 열혈자료구조
- 이스케이프 문자
- 이것이 자바다
- 메모리구조
- Algorithm
- Stack
- stream
- 윤성우의 열혈 자료구조
- s
- R
- C 언어 코딩 도장
- C programming
Archives
- Today
- Total
Engineering Note
[Spring] CommandLineRunner 본문
CommandLineRunner
- 스프링부트가 실행되고 트래픽을 받기전 실행하고 싶은 코드가 있을 때 사용하는 인터페이스
사용 예시
package com.example.demo;
import com.example.demo.entity.Member;
import com.example.demo.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
@Component
@RequiredArgsConstructor
public class DataLoader implements CommandLineRunner {
private final MemberRepository memberRepository;
@Override
public void run(String... args) {
for (int i = 1; i <= 50; i++) {
Member member = Member.builder()
.name("홍길동" + i)
.email("hong" + i + "@example.com")
.phoneNumber("010-" + String.format("%04d", i) + "-5678")
.status(Member.MemberStatus.ACTIVE)
.lastLoginAt(LocalDateTime.now().minusDays(i))
.build();
memberRepository.save(member);
}
}
}
위 코드는 프로젝트 실행시 테스트를 위해 데이터베이스에 회원데이터를 저장하는 코드다.
'Server > Spring' 카테고리의 다른 글
| [Spring] Spring Boot 프로젝트 생성시 사용 되는 개념 (0) | 2025.10.08 |
|---|---|
| [Spring] @Transactional 어노테이션과 Spring AOP의 관계 (0) | 2025.10.07 |
| [Spring] 의존성 주입(DI)과 테스트의 관계 (0) | 2025.10.01 |
| [Spring] Static Resource 경로 설정하기 (0) | 2025.09.15 |
| [Spring] @RequestParam (0) | 2025.09.15 |
Comments