CommandLineRunner


CommandLineRunner

  • インタフェース
  • アプリケーションの起動後に実行されるコード
  • @FunctionalInterface
  • アプリケーション登録@Bean、合計
  • methods

  • run(String ... args) -> void
  • @Bean
    public CommandLineRunner runner(UserEntityRepository userEntityRepository, BoardRepository boardRepository) {
    
        return args -> {
            UserEntity user = UserEntity.builder()
                .username("james")
                .password("1111")
                .email("[email protected]")
                .build();
    
            IntStream.rangeClosed(1, 200).forEach(i ->
                boardRepository.save(
                    Board.builder()
                        .title("게시글" + i)
                        .subTitle("순서 " + i)
                        .content("content")
                        .boardType(BoardType.FREE)
                        .user(user)
                        .build()
                )
            );
        };
    }