반응형

2022/03/29 3

[Java] Java8 Stream 사용법

1. 생성 List list = Arrays.asList("a", "b", "c"); //방법1 Arrays.stream(list); //방법2 list.stream(); //방법3 Stream.of("a", "b", "c"); 2. 반환타입 - 중간연산 : return Stream; filter(), map(), flatmap(), distinct(), sort(), peek(), limit(), skip() .. - 최종연산 : return 특정한 type 3. collect collect()를 구현한 collectors의 정적 메서드 - toList(), toSet(), toCollection(), toMap() list.stream().collect(Collectors.toList()); list..

Java 2022.03.29

[Spring] 스프링부트 스케줄러 사용하기

1. @SpringBootApplication 이 선언된 패키지에 @EnableScheduling 애노테이션을 선언한다. * @EnableScheduling 은 @SpringBootApplication 이 선언된 패키지 또는 하위 패키지에 붙여야 함. @SpringBootApplication @EnableScheduling public class SchedulerApplication{ public static void main(String[] args){ SpringApplication.run(SchedulerApplication.class, args); } } 2. 스케줄러를 구현할 class에 @Component 애노테이션을 선언한다. 3. 스케줄러가 되는 메서드에 @Scheduled 애노테이션을 선..

스프링 2022.03.29

[Spring] application.properties 또는 application.yml 파일에 미리 값을 지정해둔 다음 사용하기

- application.yml ( application.properties ) 파일 my-host-id: xxx.xxx.xxxx schedule: /* 10분 간격으로 03분, 13분, 23분, 33분, 43분, 53분 실행 */ TestBatch: 0 3/10 * * * * ----------------------------------------------------------------- my-host-id=xxx.xxx.xxxx schedule.TestBatch=0 3/10 * * * * - 속성 값을 사용하는 class @Slf4j @RequiredArgsConstructor @Component public class TestBatch{ @Value("${my-host-id}") private ..

스프링 2022.03.29
반응형