Spring MVC controller throws 415 error files not supported for JSON request

I've looked at all the other answers to this problem and tried most of the solutions, but nothing seems to work. I am using Dojo.xhrPOST (xhrArgs) which obviously appears after xhrArgs is defined.

my xhrArgs:

 xhrArgs = 
 {
     headers: 
     { 
       'Accept': 'application/json',
       'Content-Type': 'application/json' 
     },
  'url': thisUrl,
  'postData':requestString,
  'dataType' : 'json',
  'userId': userId,
  'measurementSystem': measurementSystem,
  'systemId': openedSystemId,
  'handleAs': 'text',
  'load': function(data)
     {
         // Replace newlines with nice HTML tags.
         data = data.replace(/\n/g, "<br/>");
         dojo.byId(target).innerHTML = data;
     },
    'error': function(error)
    {
       dojo.byId(target).innerHTML = error;
    }
};

      

and my controller method signature and annotations are as follows:

@RequestMapping(value="/saveSystemConditions", method= RequestMethod.POST,  headers =                                                                               {"content-type=application/json"})
 public String saveSystemConditions(HttpServletRequest request, HttpServletResponse response, @Valid @RequestBody Load load, BindingResult result)

      

and my requestString as shown in xhrArgs,

"{'systemID':'76', 'system.systemType':'1', 'unitsOfMeasure':'english', 'loadID':'63', 'dispersionInstallationLocation':'Duct+or+AHU', 'humidificationSystemType':'1', 'totalAirVolume':'1200.0', 'desiredDryBulb':'70.0', 'desiredAirMoistureType':'2', 'desiredAirMoisture':'55.0', 'outsideAirConditionsType':'1', 'outsideAirIntakeRateMeasuredAs':'0', 'loadCountry':'United+States', 'outsideAirVolumeMeasuredIn':'0', 'loadState':'Minnesota', 'outsideAirIntakeRate':'25.0', 'loadCity':'Minneapolis', 'elevationFeet':'837.0', 'outsideDryBulb':'-6.8', 'outsideAirMoisture':'57.3', 'userEnteredLoad':'7.43'}"

      

I get 415 (Unsupported Media Type)

Any suggestions would be much appreciated. David

+3


source to share


2 answers


It was an issue with explicitly declaring spring mvc display handlers along with <mvc:annotation-conig />

.



+1


source


Adding the following lines to the context of your application. This will fix the problem.



<mvc:default-servlet-handler/>
<mvc:annotation-driven />

      

+1









All Articles