【发布时间】:2018-06-24 21:32:56
【问题描述】:
我正在接近 Spring Boot 2 及其实现 Web 服务的反应式方法。作为几乎所有习惯使用经典同步 MVC 模式编程的人,我对这种方法有些怀疑。 我正在尝试实现一个 restcontroller 并开发一些反应式和非反应式方法作为示例的标题,以便更好地理解这些概念。 比如导入WebFlux(使用Netty作为Embedded Server)的写法,第二种和第4种方法是reactive的,第一种和第三种方法是nonreactive的吗?
@org.springframework.web.bind.annotation.RestController
public class RestController {
@Autowired
NoteDao noteDao;
/* non-reactive */
@RequestMapping("/hello")
public String sayHello(){
return "Hello pal";
}
/* reactive */
@RequestMapping("/hello/reactive")
public Mono<String> sayHelloReactively(){
return Mono.just("Hello reactively, pal!");
}
/* non-reactive */
@RequestMapping("/notes")
public List<Note> getAllNotes(){
return noteDao.findAll();
}
/* reactive */
@RequestMapping("/notes/reactive")
public Flux<List<Note>> getAllNotesReactively(){
return Flux.just(noteDao.findAll());
}
}
【问题讨论】:
标签: spring spring-boot netty reactive-programming spring-webflux