如何在Spring MVC测试中禁用Thymeleaf?

如何在Spring MVC测试中禁用Thymeleaf?,spring,spring-mvc,spring-boot,thymeleaf,Spring,Spring Mvc,Spring Boot,Thymeleaf,我正在尝试测试我的SpringMVC控制器,但我不断收到与Thymeleaf模板相关的错误。我真的不想在控制器测试中处理模板错误,因为这不是我真正感兴趣的。当模板不存在时让测试失败是可以的,但是现在我得到了与基于错误代码未找到的消息相关的错误 Caused by: org.springframework.context.NoSuchMessageException: No message found under code 'Pattern.book.name' for locale 'en'.

我正在尝试测试我的SpringMVC控制器,但我不断收到与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

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

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

spring.thymeleaf.enabled=false
检查以下答案: