Announcement Announcement Module
Collapse
No announcement yet.
Error: The attribute produces is undefined for the annotation type RequestMapping Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error: The attribute produces is undefined for the annotation type RequestMapping

    I haven't had the need to run the Roo Shell for a while on my project until today when I decided to refactor the Entity references in my project. I recently F&R'ed (Format'ed and Reseed'ed) my laptop, re-installing the latest STS and Roo. I believe prior I was at Roo 1.2.1rc1, and the latest 2.9 STS upgraded from a 2.8 install.

    Anyhow, after my pretty major refactor was done, all my Controllers now how the following errors in the aspect files:
    Code:
    The attribute produces is undefined for the annotation type RequestMapping
    Its on all the methods in the xxxController_Roo_Controller.aj files on the following annotations:
    Code:
    @RequestMapping(method = RequestMethod.POST, produces = "text/html")
    I know when I cranked up the Roo Shell, I saw this:
    Code:
    Updated ROOT/pom.xml [updated property 'roo.version' to '1.2.1.RELEASE'; updated property 'spring.version' to '3.1.0.RELEASE'; updated property 'roo.version' to '1.2.1.RELEASE'; updated property 'spring.version' to '3.1.0.RELEASE']
    But, I checked the @RequestMapping javadoc on the SpringSource site, and it shows produces as a valid member of the annotation.

    Anyone have a clue where I can look to fix this?

  • #2
    Never mind...when it updated the POM, it updated the Spring JAR versions, but didn't refresh the Eclipse project files. I ran a perform eclipse on it, refreshed, and all the errors are gone.

    Comment


    • #3
      Hi.

      I was trying to integrate Ajax using jQuery to make a POST request to Spring controller. However I am getting the following error in controller.

      "The attribute consumes is undefined for the annotation type RequestMapping"

      ​I am using spring 3.0.5 jars.

      I came across your post on the forum regarding similar issue. Can you please help?

      HTML code:

      Code:
      <html>
        <head>
        <style>
          div {
                  border: 1px solid #000000;
              }
        </style>
         
          <script src="/JSONProject/js/jquery-1.11.0.min.js"></script>
          <script>
          var user="";
          var pwd1="";
          var json="";
          var strJson="";
              $(document).ready(function(){
              
                  $("#button").click(function(){    
                      console.log("inside click");
                      user=$("#userName").val();
                      pwd1=$("#password").val();
                      json={username:user,password:pwd1};
                      console.log("json: "+json);
                      strJson=JSON.stringify(json);
                      console.log("strJson: "+strJson);
                      
                      $.ajax({
                           type: "POST",
                            url: "http://localhost:8080/JSONProject/add.html",
                            contentType: 'application/json',
                            data: JSON.stringify(json)
                        })
                        .done(function(resultUserDTO) {
                            JSON.stringify(resultUserDTO)
                            alert("result: "+resultUserDTO);
                            });
                      
                      
                  
                  });
              });
          </script>
        </head>
        <body>
        <FORM>
                  Please enter your text:
                  <BR>
                      <div  >
                          <label id="uName">Username</label>
                          <input id="userName"/>
                          <br>
                          <label id="pwd">Password</label>
                          <input id="password" type="Password" id="pwd"/>
       
                      </div>
                  <BR>
                  <INPUT id="button" TYPE="SUBMIT" VALUE="Submit">
              </FORM>
        </body>
      </html>
      Controller code:

      Code:
      package demo.controller;
      
      import org.springframework.stereotype.Controller;
      import org.springframework.web.bind.annotation.RequestBody;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RequestMethod;
      import org.springframework.web.bind.annotation.ResponseBody;
      import org.springframework.web.servlet.ModelAndView;
      
      import demo.model.Login;
      
      @Controller
      
      public class HelloWorldController {
      
          Login users;
      
          @RequestMapping("/hello")
          public ModelAndView helloWorld() {
      
              String message = "Hello World, Spring 3.0!";
              System.out.println("Inside controller");
              return new ModelAndView("hello", "message", message);
          }
      
          /**
           * Handles request for adding two numbers
           */
          @RequestMapping(value = "/add",method = RequestMethod.POST,consumes = "application/json")
          public String processJson(@RequestBody String requestBody){
      
              return "Handled application/json request ";
                              
                              
          }
      }
      Last edited by maybeam; Mar 28th, 2014, 05:21 AM.

      Comment


      • #4
        solved this issue by using 3.2.0 spring jar.
        Points learned:

        1. consumes/produces are not available for @RequestMapping in 3.0.x
        2. when using 3.2.0, asm jar is not required.

        Comment

        Working...
        X