在渲染百里叶视图之前未解析Webflow反应对象 [英] Webflux Reactive objects not resolved before rendering Thymeleaf View

查看:20
本文介绍了在渲染百里叶视图之前未解析Webflow反应对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在百里叶中呈现我的视图时,遇到错误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启动器依赖项,并且没有显式配置类。

推荐答案

我能够通过从我的pom.xml中删除以下内容来解决此问题

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>

这是由Spring starter毫无怨言地添加的,但它与Webflow准不兼容。这个应用程序运行时没有任何问题,但当它在启动日志中报告它是从Tomcat启动的,而不是Netty时,你可以感觉到出了问题。这表明它是作为老式的MVC应用程序运行的,而不是Webflow应用程序。发现这一点后,我能够找到另一个问题的解释性答案:https://stackoverflow.com/a/48418409/23276(症状不同,但答案相同)。这里还有更多的解释:https://stackoverflow.com/a/51378560/23276

我最初能够通过创建一个单依赖项示例应用程序来证明事情是可行的,该应用程序按照我在文档中所期望的和看到的方式工作。然后,我尝试逐个删除不同的依赖项,直到发现冲突。

在对此进行故障排除时,我的IDE做了一些奇怪的事情来缓存依赖项,这阻碍了我的工作。当我拖到命令行并尝试使用mvn cleanmvn spring-boot:run直到找到损坏的依赖项时,发现问题变得更容易了。

这篇关于在渲染百里叶视图之前未解析Webflow反应对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆