При загрузки страницы регистрации пользователя, на которой есть объект соответствующий классу DTO, Spring не создает объект, выдает исключение, что у класса некорректное свойство:
Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property ''userName'' of bean class [com.vs.authorizationService.DTOentity.UserDTO]: Bean property ''userName'' 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.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:612) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:104) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:228) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.web.servlet.support.BindStatus.(BindStatus.java:129) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.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] ... 88 common frames omitted
Перед этим он ещё выкидывает исключение, что у thymeleaf как раз проблемы с извлечением данного свойства у объекта:
org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "registration" - line 45, col 54) at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117) ~[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.StandaloneElementTag.beHandled(StandaloneElementTag.java:228) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE] at org.thymeleaf.engine.TemplateModel.process(TemplateModel.java:136) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
Не пойму, почему? Все проверил по 3 раза. Объект DTO, который добавляю в модель страницы:
public class UserDTO {
private String userName;
private String password;
private String repeatPassword;
private String wordCoder;
private String email;
public UserDTO() {
}
public String getUserName() {
return userName;
}
public String getPassword() {
return password;
}
public String getRepeatPassword() {
return repeatPassword;
}
public String getWordCoder() {
return wordCoder;
}
public String getEmail() {
return email;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setPassword(String password) {
this.password = password;
}
public void setRepeatPassword(String repeatPassword) {
this.repeatPassword = repeatPassword;
}
public void setWordCoder(String wordCoder) {
this.wordCoder = wordCoder;
}
public void setEmail(String email) {
this.email = email;
}
}
Контроллер:
Controller
@RequestMapping("/")
public class UserController {
@Autowired
private RequestService requestService;
@Autowired
private MessageService messageService;
@Autowired
private UserService userService;
private String repeatPasswordDontMatch="Passwords";
@GetMapping("/login")
public String getlogin()
{
return "login";
}
@PostMapping("/login")
public String login()
{
return "login";
}
@GetMapping("/registration")
public String getRegistration(Model model)
{
model.addAttribute("user", new UserDTO());
return "registration";
}
@PostMapping("/registration")
public String registrationNewUser(@Valid @ModelAttribute("user") UserDTO userDTO, BindingResult bindingResult){
if(bindingResult.hasErrors()){
//Остаемся на той же странице
return "/registration";
}
if(!userDTO.getRepeatPassword().equals(userDTO.getPassword())){
//Генерируем ошибку
bindingResult.rejectValue("password",repeatPasswordDontMatch+"не совпадают!");
return "/registration";
}
return "/registration:/login";
}
}
Фрагмент самой страницы, на которой возникает ошибка:
<div class="container">
<div class="row py-2">
<div class="col-12">
<form th:action="@{/registration}" method="post" th:object="${user}">
<div class="form-group">
<label for="username">User name</label>
<input type="text" id="username" th:field="*{'userName'}" class="form-control" placeholder="Enter user name">
<small class="form-text text-danger" th:each="err : ${#fields.errors('userName')}" th:text="${err}">Validation error</small>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" th:field="*{'password'}" class="form-control" placeholder="Password">
<small class="form-text text-danger" th:each="err : ${#fields.errors('password')}" th:text="${err}">Validation error</small>
</div>
<div class="form-group">
<label for="repeatPassword">Repeat password</label>
<input type="password" id="repeatPassword" th:field="*{'repeatPassword'}" class="form-control" placeholder="Repeat password">
<small class="form-text text-danger" th:each="err : ${#fields.errors('repeatPassword')}" th:text="${err}">Validation error</small>
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
</div>
</div> </div>
Вот в этой строке возникает исключения Таймлиф:
<input type="text" id="username" th:field="*{'userName'}" class="form-control" placeholder="Enter user name">