【发布时间】:2020-08-11 16:13:48
【问题描述】:
当我尝试在 Thymeleaf 中呈现我的视图时,我收到错误 Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'currentTemperature' cannot be found on object of type 'reactor.core.publisher.MonoMapFuseable' - maybe not public or not valid?
Spring WebFlux 文档指出“具有反应式类型包装器的模型属性被解析为其实际值”,但是将 Mono 作为模型传递给视图会给我上述错误。
@RequestMapping(path = "/")
@GetMapping
public String home(Model model) {
Mono<ThermostatState> thermostatState = thermostatClient.fetchThermostatState();
model.addAttribute("thermostatState", thermostatState);
return "home";
}
阻塞 Mono 并解开内部值使模板呈现不变,但有点消除了使用响应式库的意义。
@RequestMapping(path = "/")
@GetMapping
public String home(Model model) {
Mono<ThermostatState> thermostatState = thermostatClient.fetchThermostatState();
ThermostatState unwrappedState = thermostatState.block();
model.addAttribute("thermostatState", unwrappedState);
return "home";
}
项目完全依赖spring starter依赖,没有显式的配置类。
【问题讨论】:
标签: java thymeleaf spring-webflux