Results 1 to 3 of 3

Thread: Annotation Configuration Confusion

  1. #1
    Join Date
    Dec 2008
    Posts
    2

    Default Annotation Configuration Confusion

    I recently attended Keith Donald's presentation on "Developing Rich Web Applications with Spring." Keith demonstrated some annotation based configuration capabilities with Spring MVC that I am having a hard time duplicating. His example was

    AT-Controller
    public class HotelsController {
    AT-RequestMapping
    public void index(...) {...}
    AT-RequestMapping
    public void show(...) {...}
    AT-RequestMapping
    public void update(...) {...}
    }

    where /hotels/index would automatically map to HotelsController.index(), etc.

    I can make this occur using the AT-RequestMapping("/hotels/index") explicit declaration but not the implicit /controller/method form.

    I am using Spring 2.5.6 and have the DefaultAnnotationHandlerMapping, AnnotationMethodHandlerAdapter, and component-scan declarations in my servlet.xml.

    Am I misunderstanding something? Do I have some configuration missing? Is this possible with Spring 2.5?

    Thanks for any help,

    Joe Skora

    (Please replace "AT-" above with "at" symbol which is producing an error when I am trying to post this.)

  2. #2
    Join Date
    Dec 2008
    Posts
    2

    Default Partially resolved

    I have gotten this working as I expect but I am not sure I completely understand the solution.

    1. I added an @RequestMapping to the controller so the code is now
      Code:
      @Controller
      @RequestMapping
      public class HotelsController {
         @RequestMapping
         public void index(...) {...}
         @RequestMapping
         public void show(...) {...}
         @RequestMapping
         public void update(...) {...}
      }
    2. I also added a ControllerClassNameHandlerMapping reference and removed the DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter references, so my servlet.xml resembles
      Code:
      <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
      <context:component-scan base-package="..."/>


    I am still left wondering why this works and the other mapping handlers did not. I can't find a complete resource that defines how these handlers work individually and together.

    Thanks,

    Joe

  3. #3
    Join Date
    May 2008
    Location
    Central Florida, U.S.A.
    Posts
    36

    Default

    Actually, the @RequestMapping on the Controller is no longer being used to map the URL to the Controller. Instead it is now using the ControllerClassNameHandlerMapping to map the HotelsController to /hotels/*. See this JavaDoc for details.

    Are your method signatures different for each method? If so then that is how it is finding the correct method. When using Java 5+ and DispatcherServlet the DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter are automatically registered. In this case the AnnotationMethodHandlerAdapter is still being used.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •