0
私はspring 4.2.5とjava8に問題があります。java8 spring 4.2.5 java.util.Optionalに変換できません
@RequestMapping(value = "raw2", method = RequestMethod.GET)
ResponseEntity<String> getTest(@RequestParam Optional<String> p) {
return new ResponseEntity<>(HttpStatus.OK);
}
しかし、エラーを得続ける:
2016-04-05 20:51:41,436 DEBUG [o.s.web.servlet.DispatcherServlet] DispatcherServlet with name 'dispatcher' processing GET request for [/internal/raw2]
2016-04-05 20:51:41,438 DEBUG [o.s.w.s.m.a.DefaultAnnotationHandlerMapping] Mapping [/internal/raw2] to HandlerExecutionChain with handler [com.test.con] and 1 interceptor
2016-04-05 20:51:41,440 DEBUG [o.s.web.servlet.DispatcherServlet] Last-Modified value for [/internal/raw2] is: -1
2016-04-05 20:51:41,453 DEBUG [org.springframework.beans.BeanUtils] No property editor [java.util.OptionalEditor] found for type java.util.Optional according to 'Editor' suffix convention
2016-04-05 20:51:41,453 DEBUG [o.s.w.s.m.a.AnnotationMethodHandlerExceptionResolver] Resolving exception from handler [com.test.con]: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type [java.lang.String] to required type [java.util.Optional]; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Optional]: no matching editors or conversion strategy found
2016-04-05 20:51:41,454 DEBUG [o.s.w.s.m.a.ResponseStatusExceptionResolver] Resolving exception from handler [com.test.con]: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type [java.lang.String] to required type [java.util.Optional]; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Optional]: no matching editors or conversion strategy found
2016-04-05 20:51:41,454 DEBUG [o.s.w.s.m.s.DefaultHandlerExceptionResolver] Resolving exception from handler [com.test.con]: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type [java.lang.String] to required type [java.util.Optional]; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Optional]: no matching editors or conversion strategy found
2016-04-05 20:51:41,454 WARN [o.s.w.s.m.s.DefaultHandlerExceptionResolver] Failed to convert request element: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type [java.lang.String] to required type [java.util.Optional]; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Optional]: no matching editors or conversion strategy found
RequestParamに値属性が定義されていないと、つまりバインドする要求パラメータがありません。 – Bax
http://stackoverflow.com/questions/29804388/how-does-spring-mvc-convert-requestparam-values – hahn
これは愚かに聞こえるかもしれませんが、そのような質問が私に過去に2回以上助けてくれたと私に聞いています。あなたはこのバージョンのSpringを使用していることを完全に肯定していますか?例えば。 mavenとlinux/osxの場合、最もシンプルで信頼性の高いものです(これらのものについてはIDEを完全に信用していません)。これは 'mvn dependency:tree | grep -E "$ | spring-" ' –