- Saved searches
- Use saved searches to filter your results more quickly
- Failed to Instantiate Java 8 Date and Time class if perform direct parameter binding [SPR-13362] #17946
- Failed to Instantiate Java 8 Date and Time class if perform direct parameter binding [SPR-13362] #17946
- Comments
- Spring Boot + LocalDate: «Нет основного или конструктора по умолчанию»
- Spring Boot + LocalDate: «Нет основного или конструктора по умолчанию»
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to Instantiate Java 8 Date and Time class if perform direct parameter binding [SPR-13362] #17946
Failed to Instantiate Java 8 Date and Time class if perform direct parameter binding [SPR-13362] #17946
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don’t feel we should currently apply
Comments
Simon Wong opened SPR-13362 and commented
Failed to Instantiate Java 8 Date and Time class if perform direct parameter binding
@RestController @RequestMapping("some_path") public class MyController < @RequestMapping(value = "/my_sub_path", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public void test(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate myDate) < // throws org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.time.LocalDate]: No default constructor found; >>
There are several workaround with their own limitations
@RestController @RequestMapping("some_path") public class MyController < @ModelAttribute LocalDate myDate() < return LocalDate.now(); >@RequestMapping(value = "/my_sub_path", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public void test(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @ModelAttribute LocalDate myDate) < // It could instantiate the LocalDate class, but it WILL NOT do any data binding from web parameter also called "myDate" >>
@RestController @RequestMapping("some_path") public class MyController < @ModelAttribute LocalDate myDate() < return LocalDate.now(); >@RequestMapping(value = "/my_sub_path", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public void test(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @RequestParam @ModelAttribute LocalDate myDate) < // Works perfectly if explicit @RequestParam or @RequestParam("myDate") annotation is provided >>
@RestController @RequestMapping("some_path") public class MyController < @RequestMapping(value = "/my_sub_path", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public void test(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @RequestParam LocalDate myDate) < // This will also create a LocalDate model attribute impliclity and works perfectly!! >>
Affects: 4.1.2
The text was updated successfully, but these errors were encountered:
Spring Boot + LocalDate: «Нет основного или конструктора по умолчанию»
Это, конечно, правильно, но, насколько я понимаю, не имеет значения, потому что, согласно документации: «[. ] аннотация @DateTimeFormat должна работать с java.time на Java 8 и Spring 4.» Метод контроллера:
@PostMapping("/users") public String register(String user, String pw, @DateTimeFormat(iso=DateTimeFormat.ISO.DATE) LocalDate beginning) < MyUser myUser = MyUser.create(user,pw); MyUser.setEnabled(beginning); repo.register(myUser); return "redirect:/users/"+user; >
org.springframework.boot spring-boot-dependencies 2.0.4.RELEASE pom import org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web . 1.8
. Registrierte Nutzer
Name Freigeschaltet ab Freigeschaltet bis Passwort gesetzt Freigaben
Neuen Benutzer Registrieren
Spring Boot + LocalDate: «Нет основного или конструктора по умолчанию»
Я создал простую форму с для приложения Spring Boot. Я бы хотел, чтобы это превратилось в LocalDate в контроллере. Я получаю ошибку:
Fri Aug 17 15:32:01 CEST 2018 There was an unexpected error (type=Internal Server Error, status=500). No primary or default constructor found for class java.time.LocalDate
Это, безусловно, правильно, но — насколько я понимаю — не должно иметь значения, потому что, согласно документации: «[. ] @DateTimeFormat аннотация должна работать с java.time на Java 8 и Spring 4.»
@PostMapping("/users") public String register(String user, String pw, @DateTimeFormat(iso=DateTimeFormat.ISO.DATE) LocalDate beginning) < MyUser myUser = MyUser.create(user,pw); MyUser.setEnabled(beginning); repo.register(myUser); return "redirect:/users/"+user; >
org.springframework.boot spring-boot-dependencies 2.0.4.RELEASE pom import org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web . 1.8
. Registrierte Nutzer
Name Freigeschaltet ab Freigeschaltet bis Passwort gesetzt Freigaben
Neuen Benutzer Registrieren