इस स्प्रिंग बूट एप्लिकेशन को देखते हुए:
@SpringBootApplication
@RestController
public class ShowCase {
public static void main(String[] args) {
SpringApplication.run(ShowCase.class, args);
}
@RequestMapping(value = "submit", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public void getFormKeys(@RequestBody MultiValueMap<String, String> formData) {
System.out.println(formData.keySet().stream().collect(joining(",")));
}
}
और यह कर्ल अनुरोध:
curl -X PUT -H "Content-Type: application/x-www-form-urlencoded" --data "arg1=val&arg2=val" http://localhost:8080/submit
स्प्रिंग बूट 1.2.5 के साथ विधि को सही ढंग से लागू किया जाता है और फॉर्म-की को प्रिंट करता है।
स्प्रिंग बूट 1.3.8 के साथ विधि लागू नहीं की जाती है, लेकिन इसके बजाय एक चेतावनी लॉग की जाती है:
WARN 17844 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public void web.ShowCase.getFormKeys(org.springframework.util.MultiValueMap<java.lang.String, java.lang.String>)
स्प्रिंग बूट 1.3.8 में क्या आवश्यक है ताकि यह पुट अनुरोध फिर से काम कर सके?
4
Roland Weisleder
26 जिंदा 2017, 14:14
1 उत्तर
सबसे बढ़िया उत्तर
@EnableWebMvc एनोटेशन जोड़ें:
@SpringBootApplication
@RestController
@EnableWebMvc
public class ShowCase {
public static void main(String[] args) {
SpringApplication.run(ShowCase.class, args);
}
@RequestMapping(value = "submit", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public void getFormKeys(@RequestBody MultiValueMap<String, Object> formData) {
System.out.println(formData.keySet().stream().collect(Collectors.joining(",")));
}
}
4
Alessandro Moraes
26 जिंदा 2017, 15:04
संबंधित सवाल
नए सवाल
java
जावा एक उच्च स्तरीय प्रोग्रामिंग भाषा है। इस टैग का उपयोग तब करें जब आपको भाषा का उपयोग करने या समझने में समस्या हो। इस टैग का उपयोग शायद ही कभी किया जाता है और इसका उपयोग अक्सर [वसंत], [वसंत-बूट], [जकार्ता-ई], [Android], [javafx], [हडूप], [श्रेणी] और [मावेन] के साथ किया जाता है।
Normally you would add @EnableWebMvc for a Spring MVC app, but Spring Boot adds it automatically when it sees spring-webmvc on the classpath. This flags the application as a web application and activates key behaviors such as setting up a DispatcherServlet.
[spring.io/ गाइड/जीएस/स्प्रिंग-बूट/](स्रोत)