Java 类org.springframework.boot.ApplicationRunner 实例源码
项目:spring-five-functional-reactive
文件:WebfluxDemo.java
/**
* 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();
};
}
项目:ReactiveTest
文件:Spring5Application.java
@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");
};
}
项目:testing-101
文件:CustomerServiceApplication.java
@Bean
ApplicationRunner applicationRunner(CustomerRepository customerRepository) {
return args -> {
Stream.of("a", "b", "c")
.forEach(n -> customerRepository.save(new Customer(null, n, n,
n + "@" + n + ".com")));
};
}
项目:spring-five-functional-reactive
文件:WebfluxFnConfiguration.java
/**
* 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();
}
项目:boot-works
文件:BootApplication.java
@Bean
ApplicationRunner init(BookRepository repository) {
// init db
return args -> {
repository.save(new Book("Java tutorial", 1995));
repository.save(new Book("Spring reference", 2016));
};
}
项目:boot-works
文件:BootApplication.java
@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);
}
项目:reactive-matchday
文件:MatchDayWebApplication.java
@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();
};
}
项目:spring-cloud-skipper
文件:ShellConfiguration.java
@Bean
public ApplicationRunner helpAwareShellApplicationRunner() {
return new HelpAwareShellApplicationRunner();
}
项目:spring-cloud-skipper
文件:ShellConfiguration.java
@Bean
public ApplicationRunner initializeConnectionApplicationRunner(TargetHolder targetHolder,
@Qualifier("main") ResultHandler<Exception> resultHandler,
SkipperClientProperties skipperClientProperties) {
return new InitializeConnectionApplicationRunner(targetHolder, resultHandler, skipperClientProperties);
}
项目:spring-cloud-skipper
文件:ShellConfiguration.java
@Bean
public ApplicationRunner applicationRunner(Shell shell, ConfigurableEnvironment environment) {
return new InteractiveModeApplicationRunner(shell, environment);
}
项目:cdct
文件:CustomerServiceApplication.java
@Bean
ApplicationRunner init(CustomerRepository repository) {
return args ->
Stream.of("a", "b", "c")
.forEach(n -> repository.save(new Customer(n, n, n + "@" + n + ".com")));
}
项目:cdct
文件:CustomerServiceApplication.java
@Bean
ApplicationRunner init(CustomerRepository repository) {
return args ->
Stream.of("a", "b", "c")
.forEach(n -> repository.save(new Customer(n, n, n + "@" + n + ".com")));
}
项目:cdct
文件:CustomerServiceApplication.java
@Bean
ApplicationRunner init(CustomerRepository repository) {
return args ->
Stream.of("a", "b", "c")
.forEach(n -> repository.save(new Customer(n, n, n + "@" + n + ".com")));
}
项目:cdct
文件:CustomerServiceApplication.java
@Bean
ApplicationRunner init(CustomerRepository repository) {
return args ->
Stream.of("a", "b", "c")
.forEach(n -> repository.save(new Customer(n, n, n + "@" + n + ".com")));
}
项目:datadog-jmx-collector
文件:JmxCollectorMain.java
@Bean
public ApplicationRunner applicationRunner() {
return new JmxCollector( collectorMetrics(), configFile, taskScheduler(), taskExecutor(), pollRateMs, jmxConnectionStateResolver(), statsdClient(), objectMapper() );
}
项目:spring-cloud-stream
文件:SampleStreamApp.java
@Bean
public ApplicationRunner runner(PollableMessageSource pollableSource) {
return args -> pollableSource.poll(message -> {
System.out.println("Polled payload: " + message.getPayload());
});
}