Template Parsing Error with Thymeleaf 3 and Spring Boot 2.1

Carl

Hopefully this isn't a repeated question but I've spent some time searching and couldn't find anyone with the same problem or useful resolution. I've created a new application using Spring Initializr with the following dependencies for a simple web app that access kafka:

Web, DevTools, JPA, MySQL, Kafka, and Security

I followed a paired down version of a previous application I created in Spring Boot 1.5.14 and Thymeleaf 3 but cannot get my basic login form to work - I keep getting a template parsing error as follows:

There was an unexpected error (type=Internal Server Error, status=500).
An error happened during template parsing (template: "class path resource [templates/index.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/index.html]") at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100) at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666) at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362) at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1370) at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1116) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:890) at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: org.attoparser.ParseException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "index" - line 12, col 37) at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) at org.attoparser.MarkupParser.parse(MarkupParser.java:257) at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ... 52 more Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "index" - line 12, col 37) at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117) at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) at org.thymeleaf.engine.ProcessorTemplateHandler.handleStandaloneElement(ProcessorTemplateHandler.java:918) at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleStandaloneElementEnd(TemplateHandlerAdapterMarkupHandler.java:260) at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler$InlineMarkupAdapterPreProcessorHandler.handleStandaloneElementEnd(InlinedOutputExpressionMarkupHandler.java:256) at org.thymeleaf.standard.inline.OutputExpressionInlinePreProcessorHandler.handleStandaloneElementEnd(OutputExpressionInlinePreProcessorHandler.java:169) at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler.handleStandaloneElementEnd(InlinedOutputExpressionMarkupHandler.java:104) at org.attoparser.HtmlElement.handleStandaloneElementEnd(HtmlElement.java:79) at org.attoparser.HtmlMarkupHandler.handleStandaloneElementEnd(HtmlMarkupHandler.java:241) at org.attoparser.MarkupEventProcessorHandler.handleStandaloneElementEnd(MarkupEventProcessorHandler.java:327) at org.attoparser.ParsingElementMarkupUtil.parseStandaloneElement(ParsingElementMarkupUtil.java:96) at org.attoparser.MarkupParser.parseBuffer(MarkupParser.java:706) at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:301) ... 54 more Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' available as request attribute at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153) at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903) at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227) at org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306) at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:253) at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227) at org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174) at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ... 67 more

The relevant error appears to be here: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "index" - line 12, col 37)

That corresponds to the following block of index.html code:

<form method="post" style="max-width:600px;" th:object="${user}">
    <div class="form-group">
        <label th:for="username">Username</label>
        <input class="form-control" th:field="*{username}" />
        <span th:errors="*{username}" class="error"></span>
    </div>
    <input type="submit" value="Play" />
</form>

More specifically, to the "th:field" . Now this worked perfectly in my older application, but cannot even get my index.html page to run. Any idea what is happening? Is there some changes in Spring that is impacting this?

And this is my Controller:

@RequestMapping(value = "index", method = RequestMethod.GET)
public String displayLogin(Model model) {
    model.addAttribute("title", "Welcome to Kafka Jeopardy");
    model.addAttribute("user", new User());
    return "index";
}

And my User object:

@Entity
public class User {

@Id
@GeneratedValue
private int id;

@NotNull
@Size(min = 3, max = 15)
private String username;

public User() {
}

public User(String username) {
    this.username = username;
}

public int getId() {
    return this.id;
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}
}

Any insight would be appreciated!

Carl

I solved it by downgrading Spring Boot to 1.5. Syntax then worked. Can't find information in either Spring or Thymeleaf docs but clearly something to do with the version.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Thymeleaf + Spring MVC - Thymeleaf template parsing error on using checkbox input

Thymeleaf template parsing error

Thymeleaf exceptions for resolving template in spring boot

How to handle Whitelabel 404 error in Spring Boot without using Thymeleaf or other template engines

Thymeleaf Layout Dialect 'An Error Happened During Template Parsing'

Spring boot Thymeleaf context parameter is not passed to template

Error occuring template parsing. (Spring Boot + Thymeleaf)

How to locate Thymeleaf template from spring boot

Issue with spring boot's thymeleaf auto configuration trying to resolve error template for rest application

Spring Boot and Thymeleaf Neko HTML Error

Adding Custom Thymeleaf Template Resolver to Spring Boot

Spring boot + Thymeleaf custom error messages

Thymeleaf: Thymeleaf template parsing error

Template parsing error: template: :1: unclosed action

Several template locations for Thymeleaf in Spring Boot

Spring Boot + Thymeleaf CSS file cannot access and have 500 error no template found

Thymeleaf; "an error happened during template parsing"

error with spring template parsing

Thymeleaf, Spring Boot 2: invalid path to resources when handle error

Spring boot - Thymeleaf template - multiple resolvers

Spring Boot - Thymeleaf template

Spring boot with Thymeleaf 3 Beta

spring boot calling thymeleaf template failed

Spring Boot + Thymeleaf css is not applied to template

An error happened during template parsing using Spring Boot

Spring Boot Thymeleaf Parsing Error on index.html under src/main/resources/templates/

Error during template parsing.Spring boot and Thymeleaf

Spring Boot Thymeleaf Whitelabel Error Page

How can resolve this error Template parsing error in thymeleaf