Я новичок в Spring boot
.Весенний ботинок с остальными услугами
Я пытаюсь написать код, который использует почтовый запрос как вход.
Я получаю эту ошибку, когда пытаюсь отправить запрос на сообщение через клиентский клиент chrome plugin.
Я использую Инструмент для сборки Maven.
{
"timestamp": 1431079188726,
"status": 415,
"error": "Unsupported Media Type",
"exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
"message": "Content type 'text/plain;charset=UTF-8' not supported",
"path": "/api/greetings" }
Это классы.
Application.java
@SpringBootApplication
@ComponentScan(basePackages="webapi")
public class Application {
public static void main(String[] args) throws Exception{
SpringApplication.run(Application.class, args);
}
}
Greeting.java
public class Greeting {
private BigInteger id;
private String text;
public Greeting() {
}
public BigInteger getId() {
return id;
}
public void setId(BigInteger id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
GreetingController.java
@RestController
public class GreetingController {
private static BigInteger nextId;
private static Map<BigInteger, Greeting> greetingMap;
private static Greeting save(Greeting greeting) {
if (greetingMap == null) {
greetingMap = new HashMap<BigInteger, Greeting>();
nextId = BigInteger.ONE;
}
greeting.setId(nextId);
nextId = nextId.add(BigInteger.ONE);
greetingMap.put(greeting.getId(), greeting);
return greeting;
}
static {
Greeting g1 = new Greeting();
g1.setText("Hello World");
save(g1);
Greeting g2 = new Greeting();
g2.setText("Hola Mundo!");
save(g2);
}
@RequestMapping(value = "/api/greetings", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Collection<Greeting>> getGreetings() {
Collection<Greeting> greetings = greetingMap.values();
return new ResponseEntity<Collection<Greeting>>(greetings,
HttpStatus.OK);
}
@RequestMapping(value = "/api/greetings/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Greeting> getGreeting(
@PathVariable("id") BigInteger id)
{
Greeting greeting = greetingMap.get(id);
if (greeting == null) {
return new ResponseEntity<Greeting>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<Greeting>(greeting, HttpStatus.OK);
}
@RequestMapping(value = "/api/greetings", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<Greeting> createGreeting(
@RequestBody Greeting greeting) {
Greeting savedGreeting = save(greeting);
return new ResponseEntity<Greeting>(savedGreeting, HttpStatus.CREATED);
}
}
@ KunalMalhotra помогло? – Vihar