Arquivo da categoria: Spring

Spring Profiles

Spring Profiles provide a way to segregate parts of your application configuration and make it only available in certain environments. Any @Component or @Configuration can be marked with @Profile to limit when it is loaded:

public class ProductionConfiguration {

    // ...


In the normal Spring way, you can use a Environment property to specify which profiles are active. You can specify the property in any of the usual ways, for example you could include it in your,hsqldb

or specify on the command line using the switch,hsqldb.

Share and Enjoy !

0 0

Spring MVC: Don’t deserialize JSON request body

You will usually see this type of error when Spring MVC finds a request mapping that matches the URL path but the parameters (or headers or something) don’t match what the handler method is expecting.

If you use the @RequestBody annotation then I believe Spring MVC is expecting to map the entire body of the POST request to an Object. I’m guessing your body is not simply a String, but some full JSON object.

If you have a java model of the JSON object you are expecting then you could replace the String parameter with that in your doSomething declaration, such as

public void doSomething(@RequestBody MyObject myobj) {

If you don’t have a Java object that matches the JSON then you could try to get it working by replacing the String type with a Map<String, Object> and see if that gets you closer to a working solution.

You could also turn on debug logging in Spring MVC to get more information on why it was a bad request.

Edit: Given your requirements in the comments, you could simply inject the HttpServletRequest into your method and read the body yourself.

public void doSomething(HttpServletRequest request) {
  String jsonBody = IOUtils.toString( request.getInputStream());
  // do stuff

Share and Enjoy !

0 0