2014-03-13 4 views
8

Ich benutze springMVC und ich bekomme folgende Ausnahme beim Versuch, ein Update zu tun.Spring mvc werfen org.springframework.web.HttpMediaTypeNotAcceptableException: Konnte keine akzeptable Darstellung finden

10:10:49,847 DEBUG LogicalConnectionImpl:250 - Released JDBC connection 
10:10:49,859 DEBUG FixedContentNegotiationStrategy:48 - Requested media types is text/html (based on  default MediaType) 
10:10:49,929 DEBUG ExceptionHandlerExceptionResolver:132 - Resolving exception from handler [public com.model.JobQueue com.controller.TestResultController.updateJob(java.lang.String,java.lang.String,java.lang.String)]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation 
10:10:49,937 DEBUG ResponseStatusExceptionResolver:132 - Resolving exception from handler [public com.model.JobQueue com.controller.TestResultController.updateJob(java.lang.String,java.lang.String,java.lang.String)]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation 
10:10:49,938 DEBUG DefaultHandlerExceptionResolver:132 - Resolving exception from handler [public com.model.JobQueue com.controller.TestResultController.updateJob(java.lang.String,java.lang.String,java.lang.String)]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation 
10:10:49,940 DEBUG DispatcherServlet:999 - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling 
10:10:49,940 DEBUG DispatcherServlet:966 - Successfully completed request 
10:10:49,941 DEBUG DefaultListableBeanFactory:246 - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor' 

Folgendes ist die Controller-Methode, die die Ausnahme auslöst. Gibt es etwas, was ich tun muss, damit dies funktioniert?

@RequestMapping(value="/updateJob", method=RequestMethod.GET) 
public @ResponseBody JobQueue updateJob(@RequestParam(value="job_id") String job_id, @RequestParam String test_id, @RequestParam(value="status") String status) { 
    JobQueue job = jobqueueService.getJob(Integer.parseInt(job_id)); 
    job.setTest_id(test_id); 
    job.setStatus(Integer.parseInt(status)); 
    jobqueueService.updateJob(job); 
    return job; 
} 

fand ich folgenden Beitrag Spring MVC - HttpMediaTypeNotAcceptableException wo ähnliches Problem diskutiert wurde, aber ich bin nicht sicher, wie über die Lösung dieses mit Anmerkung zu gehen.

Irgendeine Idee?

Antwort

6

Die Ausnahme wurde aufgrund des Rückgabewerts des Controllers ausgelöst. Sobald ich den Rückgabewert geändert hatte, ging die Ausnahme weg.

public @ResponseBody String updateJob(@RequestParam(value="job_id") String job_id){ 

Ich änderte auch die Antwort auf null.

@RequestMapping(value="/updateJob", method=RequestMethod.GET) 
public @ResponseBody String updateJob(@RequestParam(value="job_id") String job_id){ 
    Integer jobid = Integer.parseInt(job_id); 

    JobQueue job = jobqueueService.getJob(jobid); 
    . 
    . 
    return null; 
} 
+3

jedoch klein es ist. Dennoch ist es eine wertvolle Frage mit wertvoller Antwort. Ich habe es an einem Ort richtig und ich habe es einfach vergessen. Dies half mir, meinen Fehler schnell zu finden. Also ignoriere diese Frage nicht. Vielen Dank!! –

+3

@ user1647708: Was ist, wenn mein Rückgabetyp Liste ist? Was soll ich zurückgeben? –

1

u kann dies versuchen:

@RequestMapping(value = "audit/unaudit", method = RequestMethod.GET,produces = "application/json") 
Verwandte Themen