【问题标题】:How to disable Thymeleaf in Spring MVC tests?如何在 Spring MVC 测试中禁用 Thymeleaf?
【发布时间】:2017-06-27 12:11:50
【问题描述】:

我正在尝试测试我的 Spring MVC 控制器,但我不断收到与 Thymeleaf 模板相关的错误。我真的不想在控制器测试中处理模板错误,因为这不是我真正感兴趣的。当模板不存在时测试失败是可以的,但现在我收到与消息相关的错误不根据错误码找到。

Caused by: org.springframework.context.NoSuchMessageException: No message found under code 'Pattern.book.name' for locale 'en'.
    at org.springframework.context.support.DelegatingMessageSource.getMessage(DelegatingMessageSource.java:84)
    at org.springframework.context.support.AbstractApplicationContext.getMessage(AbstractApplicationContext.java:1264)
    at org.springframework.web.servlet.support.RequestContext.getMessage(RequestContext.java:733)
    at org.springframework.web.servlet.support.BindStatus.initErrorMessages(BindStatus.java:181)
    at org.springframework.web.servlet.support.BindStatus.getErrorMessages(BindStatus.java:277)
    at org.thymeleaf.spring4.processor.attr.SpringErrorsAttrProcessor.processAttribute(SpringErrorsAttrProcessor.java:82)
    at org.thymeleaf.processor.attr.AbstractAttrProcessor.doProcess(AbstractAttrProcessor.java:87)
    at org.thymeleaf.processor.AbstractProcessor.process(AbstractProcessor.java:212)
    ... 119 more

运行应用程序时不存在此问题。我一直在试图弄清楚如何设置测试环境来解决这个问题,但是我找不到任何可行的方法。现在,我只是在努力让控制器代码正常工作。

【问题讨论】:

标签: spring spring-mvc spring-boot thymeleaf


【解决方案1】:

您可以在测试应用程序属性文件中禁用 Thymeleaf is Spring boot 2+

spring.thymeleaf.enabled=false

【讨论】:

    猜你喜欢
    • 2017-03-15
    • 2020-02-15
    • 2016-11-05
    • 2014-02-18
    • 2019-03-25
    • 2012-10-25
    • 1970-01-01
    • 2018-01-07
    • 2018-06-12
    相关资源
    最近更新 更多