Java Magazine, Jan/Feb 2018
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2018 66 reactive programming Next create a Spring Data repository to support the data management lifecycle of the entity This should look very familiar to anyone who has ever used Spring Data except that the repository supports reactive interactions methods return Publisher types and input can be given as Publisher instances See Listing 7 Listing 7 A reactive Spring Data MongoDB repository package com example libraryservice import org springframework data mongodb repository ReactiveMongoRepository import reactor core publisher Flux public interface BookRepository extends ReactiveMongoRepository Flux findByAuthor String author Install Some Sample Data With that you now have enough to install some sample data just for your demo Spring Boot invokes the run ApplicationArguments method when the application has started passing wrappers for the arguments String args into the application Lets create an ApplicationRunner that deletes all the data in the data source then emits a few book titles then maps them to Book entities and then persists those books Finally it queries all the records in the data source and then prints out everything Listing 8 shows all this Listing 8 An ApplicationRunner to write data package com example libraryservice import lombok extern slf4j Slf4j import org springframework boot ApplicationArguments import org springframework boot ApplicationRunner
You must have JavaScript enabled to view digital editions.