I am making simple Spring MVC web application. In my application I want to send a object from front end to Spring controller method. But when I do this I am getting js error
500 (Internal Server Error)
I tried to find a good answer in internet but still could not find a good one.
My controller method is
@RequestMapping(value = "/add", method = RequestMethod.GET, consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody String addInventory(@RequestBody InventoryAddParam inventoryAddParam) {
log.info("addInventory");
ServiceRequest<InventoryAddParam> serviceRequest = convertAddParamtoServiceRequest(inventoryAddParam);
validate(inventoryAddParam);
inventoryService.addInventory(serviceRequest);
return "Inventory Added Succesfully";
}
inventoryAddParam is a Serializable object that contain only String parameters.
My JavaScript function to send object is
function sendDataTest() {
$.ajax({
url : "/GradleSpringMVC/inventory/add",
type : 'GET',
dataType : 'json',
data : JSON.stringify(populateTestObject()),
contentType : 'application/json',
mimeType : 'application/json'
}).done(function(data) {
// temGrid.addJSONData(data);
}).fail(function(error) {
// parseToPageAlerts(error.responseText);
}).always(function() {
// hideLoading()
});}
I am creating the addParam object to send as ajax call. It create in function
function populateTestObject(){
var addParam = new InventoryAddParam();
addParam.inventoryId = "INV001";
addParam.name = "ECG MACHINE";
addParam.price = "1000";
addParam.hospital = "Colombo";
addParam.userNote = "User Note";
return addParam;}
Do I have done any wrong thing here ?
Other details about the error
Remote Address:127.0.0.1:8080
Request URL:http://localhost:8080/GradleSpringMVC/inventory/add
Request Method:POST
Status Code:500 Internal Server Error
Header
Connection:close
Content-Language:en
Content-Length:4939
Content-Type:text/html;charset=utf-8
Date:Wed, 21 Jan 2015 03:55:19 GMT
Server:Apache-Coyote/1.1