1

I'm trying to test my Spring MVC controller, but I keep getting errors related to Thymeleaf templates. I really don't want deal with template errors in the controller test since that's not really what I'm interested in. Having the tests fail when templates don't exist is ok, but right now I'm getting errors relating to messages not being found based on error code.

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

This problem does not exist when I run the application. I've been trying to figure out how to set up the test environment to resolve this, but there I can't find anything that works. Right now, I'm just really trying to get the controller code working properly.

Psycho Punch
  • 6,418
  • 9
  • 53
  • 86
  • check this answer: http://stackoverflow.com/questions/24999469/how-to-unit-test-a-secured-controller-which-uses-thymeleaf-without-getting-temp – DimaSan Feb 09 '17 at 22:10

1 Answers1

2

You can disable Thymeleaf is Spring boot 2+ in your test application properties file

spring.thymeleaf.enabled=false
gmode
  • 3,601
  • 4
  • 31
  • 39