[JAVA] A story that made me regret when a "NotReadablePropertyException" occurred during the development of the Spring Boot application.

As the title suggests, I got stuck in an error and it seemed like I was looking back at the code many times. I managed to solve it by trial and error, but I couldn't help it, but I thought it could be someone else, so I'll leave it as a memorandum.

error contents

console



2019-12-27 09:13:27.304 ERROR 21044 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/mainPage.html]")] with root cause

org.springframework.beans.NotReadablePropertyException: Invalid property 'foodsName' of bean class [com.PFCbalancer.model.FormFoodsData]: Bean property 'foodsName' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
	at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:622) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:612) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:104) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:228) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:129) ~[spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903) ~[spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:253) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.engine.ProcessorTemplateHandler.handleStandaloneElement(ProcessorTemplateHandler.java:918) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleStandaloneElementEnd(TemplateHandlerAdapterMarkupHandler.java:260) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler$InlineMarkupAdapterPreProcessorHandler.handleStandaloneElementEnd(InlinedOutputExpressionMarkupHandler.java:256) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.standard.inline.OutputExpressionInlinePreProcessorHandler.handleStandaloneElementEnd(OutputExpressionInlinePreProcessorHandler.java:169) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler.handleStandaloneElementEnd(InlinedOutputExpressionMarkupHandler.java:104) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.attoparser.HtmlVoidElement.handleOpenElementEnd(HtmlVoidElement.java:92) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.attoparser.HtmlMarkupHandler.handleOpenElementEnd(HtmlMarkupHandler.java:297) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.attoparser.MarkupEventProcessorHandler.handleOpenElementEnd(MarkupEventProcessorHandler.java:402) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.attoparser.ParsingElementMarkupUtil.parseOpenElement(ParsingElementMarkupUtil.java:159) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.attoparser.MarkupParser.parseBuffer(MarkupParser.java:710) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:301) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189) ~[thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373) ~[spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118) ~[spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057) ~[spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1591) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_162]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_162]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.29.jar:9.0.29]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_162]


All of the above error statements. The core error in this is ** 2nd line **.

Does the return type of the getter match the parameter type of the setter?

By the way, when translated, it says, "The return value of the getter does not match the type of the setter."

Now that I understand it, I'm wondering if I'll take a look at the code.

Corresponding code

view(Excerpt)



<form method="post" th:action="@{/main/calcNowPFC}" th:object="${formFoodsData}">
	<div class="bottomForm__inputArea">
		<div>
			<label class="bottomForm__inputArea--label">Product name:</label>
			<input class="bottomForm__inputArea--textbox" type="text" th:field="*{foodsName}">
			<label class="bottomForm__inputArea--label">P:</label>
			<input class="bottomForm__inputArea--numberbox" type="number" th:field="*{foodsProtein}">
			<label class="bottomForm__inputArea--label">F:</label>
			<input class="bottomForm__inputArea--numberbox" type="number" th:field="*{foodsFat}">
			<label class="bottomForm__inputArea--label">C:</label>
			<input class="bottomForm__inputArea--numberbox" type="number" th:field="*{foodsCarb}">
		</div>
		<div class="bottomForm__inputArea--btn">
			<button type="submit" class="bottomForm__inputArea--btnSubmit">add</button>
		</div>
	</div>
</form>


This time ** I got an error as soon as I put the above. ** ** I also checked the following controllers such as the method, action, and binding specification method (th: object, th: field) of the form.

controller(Excerpt)



@PostMapping("/main/calcNowPFC")
	public String postMainNowPFC(@ModelAttribute FormBodyData formBodyData, FormFoodsData formFoodsData, BindingResult bindingResult, Model model) {

	foodsList.add(formFoodsData);
	model.addAttribute("foodsList",foodsList);

	model.addAttribute("label",label);
    model.addAttribute("protein",protein);
    model.addAttribute("fat",fat);
    model.addAttribute("carb",carb);
    model.addAttribute("kal",kal);

    model.addAttribute("foodsProtein",foodsProtein);
    model.addAttribute("foodsFat",foodsFat);
    model.addAttribute("foodsCarb",foodsCarb);

		return "mainPage";
}

This is the description on the controller side

After the annotation of @ModelAttribute, ** FormFoodsData formFoodsData specifies the class for binding **, and it is judged that ** Attribute can be made as an argument with Model model. ** **

BindingResult Check if you can receive the result of ** bind with bindingResult. ** **

At this point, the controller side seemed to be okay.

model(For binding)



package com.PFCbalancer.model;

import lombok.Data;

@Data
public class FormFoodsData {
	private String foodsName;
	private int foodsProtein;
	private int foodsFat;
	private int foodsCarb;
}

This is a convenient plugin that automatically generates getters and setters called lombok in model, and the getters and setters in question are not described.

For the time being, check if the class name specified in th: object on the view side is correct. th: object = "$ {formFoodsData}" and it seems that the ** uppercase letters of the variable name are automatically converted **, so ** check the match with the class name **, so there is no problem.

Check th: field = "* {foodsName}" and 3 other fields as well. This is no problem because the argument name of model is ** exactly matched. ** **

As a result of looking at the code ...

Judged that there is no problem in terms of code. Then what? What do you mean by "getter and setter types do not match" in the first place? lombok ...!

While I was investigating, I thought that I would like to reinsert Lombok and update the project. プロジェクト再起動.png

Result ... App launched: sob :: sob :: sob:

Summary

There was nothing wrong with the code this time. However, I washed the code and checked it ** It was crushed for half a day. **: disappointed_relieved: As a result, the code was able to escape the difficulty by ** re-installing the plugin and updating the project ** without any problems. : relaxed: However, I personally realized that it was a very unsettling development, or that such a development could happen as long as I was an engineer. ** **

What I want to convey in this case, and what I engraved in my heart, is not bound by the things in front of me. ** If you observe things from a wider perspective, these solutions will be quicker. Will it be? I thought ** </ font>. It's been a long time, but I would like to make it the last word.

: sunny: Have a good engineer life! : sunny:

Recommended Posts

A story that made me regret when a "NotReadablePropertyException" occurred during the development of the Spring Boot application.
A story that stumbled when deploying a web application created with Spring Boot to EC2
A story packed with the basics of Spring Boot (solved)
The story of raising Spring Boot 1.5 series to 2.1 series
When introducing JOOQ to Spring boot, a story that was dealt with because an error occurred around Liquibase
About the solution of the error that occurred when trying to create a Japanese file of devise in the Docker development environment
[Spring Boot] The story that the bean of the class with ConfigurationProperties annotation was not found
The story of raising Spring Boot from 1.5 series to 2.1 series part2
[Docker] List of errors that occurred when building the environment
Get a proxy instance of the component itself in Spring Boot
A memo that containerizes the simple chat application of Node.js + socket.io
A story that struggled with the introduction of Web Apple Pay
A story that confirmed the profile of Yasuko Sawaguchi 36 years ago
Spring Boot application development in Eclipse
Memorandum of understanding when Spring Boot 1.5.10 → Spring Boot 2.0.0
A memo that touched Spring Boot
Incident (rails) that is logged out when user editing of the application
Create a Spring Boot app development project with the cURL + tar command
A story about a Spring Boot project written in Java that supports Kotlin
The story of encountering Spring custom annotation
Story when moving from Spring Boot 1.5 to 2.1
Start web application development with Spring Boot
The story of making an Android application that can adjust the sampling frequency of the accelerometer
Sign in to a Spring Boot web application on the Microsoft ID platform
A troublesome story when deleting the gems file created in the gem development directory.
Get the path defined in Controller class of Spring boot as a list
A story confirming the implementation of the SendGrid Java library when mail delivery fails
Resource handler settings when delivering SPA with the static resource function of Spring Boot
I tried to clone a web application full of bugs with Spring Boot
How to set environment variables in the properties file of Spring boot application
Report an example of performance degradation that occurred when the argument Comparator of Arrays.sort was given by a lambda expression
[Must-see for fledgling engineers] A story that the world expanded when I actually operated a web service that I made by myself
A story that people who did iOS solidly may be addicted to the implementation of Listener when moving to Android