/** * Application runner to initialize a capped collection for {@link Event}s and insert a new {@link Event} every two * seconds. * * @param operations * @param reactiveOperations * @return */ @Bean ApplicationRunner onStart(MongoOperations operations, ReactiveMongoOperations reactiveOperations) { return args -> { CollectionOptions options = CollectionOptions.empty() // .capped() // .size(2048) // .maxDocuments(1000); operations.dropCollection(Event.class); operations.createCollection(Event.class, options); Flux.interval(Duration.ofSeconds(2)) // .map(counter -> new Event(LocalDateTime.now())) // .flatMap(reactiveOperations::save) // .log() // .subscribe(); }; }
@Bean ApplicationRunner run() { return args -> { log.debug("run"); ListenableFuture<String> s = myService.hello(); s.addCallback(a -> log.debug(a), e -> log.debug(e.getMessage())); log.debug("exit"); }; }
@Bean ApplicationRunner applicationRunner(CustomerRepository customerRepository) { return args -> { Stream.of("a", "b", "c") .forEach(n -> customerRepository.save(new Customer(null, n, n, n + "@" + n + ".com"))); }; }
/** * Initializes the repository with a sample user. * * @param repository the repository to create {@link User}s in. * @return */ @Bean ApplicationRunner onStartup(UserRepository repository) { // We need to call ….block() here to actually execute the call. return (args) -> repository.save(new User("Dave Matthews")).block(); }
@Bean ApplicationRunner init(BookRepository repository) { // init db return args -> { repository.save(new Book("Java tutorial", 1995)); repository.save(new Book("Spring reference", 2016)); }; }
@Bean ApplicationRunner initUsers(PasswordEncoder encoder, AccountRepository repository) { // init db, for demo return args -> Stream.of( new Account("user", encoder.encode("password"), "USER"), new Account("admin", encoder.encode("password"), "USER,ROLE_ADMIN")).forEach(repository::save); }
@Bean public ApplicationRunner initialize(final ReactiveMongoTemplate mongoTemplate) { return args -> { /* * INSERT ALL THE NEEDED TEST DATA (will block) */ Data.initializeAllData(mongoTemplate); /* * INITIALIZATION OF THE MATCH EVENT STREAM */ final MatchEventAgent matchEventAgent = new MatchEventAgent(mongoTemplate); final Flux<MatchEvent> matchEventStream = matchEventAgent.createAgentStream(); // Subscribe and just let it run (forever) matchEventStream.subscribe(); /* * INITIALIZATION OF THE MATCH COMMENT STREAM */ final MatchCommentAgent matchCommentAgent = new MatchCommentAgent(mongoTemplate); final Flux<MatchComment> matchCommentStream = matchCommentAgent.createAgentStream(); // Subscribe and just let it run (forever) matchCommentStream.subscribe(); }; }
@Bean public ApplicationRunner helpAwareShellApplicationRunner() { return new HelpAwareShellApplicationRunner(); }
@Bean public ApplicationRunner initializeConnectionApplicationRunner(TargetHolder targetHolder, @Qualifier("main") ResultHandler<Exception> resultHandler, SkipperClientProperties skipperClientProperties) { return new InitializeConnectionApplicationRunner(targetHolder, resultHandler, skipperClientProperties); }
@Bean public ApplicationRunner applicationRunner(Shell shell, ConfigurableEnvironment environment) { return new InteractiveModeApplicationRunner(shell, environment); }
@Bean ApplicationRunner init(CustomerRepository repository) { return args -> Stream.of("a", "b", "c") .forEach(n -> repository.save(new Customer(n, n, n + "@" + n + ".com"))); }
@Bean public ApplicationRunner applicationRunner() { return new JmxCollector( collectorMetrics(), configFile, taskScheduler(), taskExecutor(), pollRateMs, jmxConnectionStateResolver(), statsdClient(), objectMapper() ); }
@Bean public ApplicationRunner runner(PollableMessageSource pollableSource) { return args -> pollableSource.poll(message -> { System.out.println("Polled payload: " + message.getPayload()); }); }