Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC step-by-step... with annotations? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC step-by-step... with annotations?

    I tried to use the step-by-step tutorial that comes included with release 2.5.6.

    In step 1.12 it blows up with "No adapter for handler [<controller name here>]: Does your handler implement a supported interface like Controller?"

    Per the tutorial, it does implement Controller, but when double-checking the Controller code I noticed that Eclipse complains that (a) I must use the @Controller annotation, and (b) Explicitly specifying the Controller interface is considered 'duplicate' even when not using the annotation. But if I specify @Controller... it still throws the same error (probably because some 'stuff' is needed in the xml configuration).

    So, my questions are:

    1) Are Annotations now MANDATORY in release 2.5.6? If so, where do I find GOOD documentation about them?

    2) Did somebody mess up and release the wrong version of the step-by-step document with release 2.5.6?

    3) Where can I go for a proper step-by-step tutorial that will work with release 2.5.6.

    4) I am very surprised about this problem. Version 2.5.6 has been out for a while, and I can't be the first one to notice the problem. Is Spring giving up on properly documenting its open source? I hope not, because even the best software is worthless if novices at it can't figure out how to use it.

  • #2
    make sure you have the following in your applicationContext.xml/equivalent
    Code:
    <beans
      xmlns=“http://www.springframework.org/schema/beans”
      xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
      xmlns:context=“http://www.springframework.org/schema/context”
      xsi:schemaLocation=
       “http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-2.5.xsd”>
    
        <context:component-scan base-package=“org.mypackage”/>
    </beans>
    Annotate your class with @Controller and then provide a @RequestMapping annotation to either the entire class:
    Code:
    @Controller
    @RequestMapping("/foo/bar.htm")
    class myClass{
       @RequestMapping(method = RequestMethod.GET)
       public void get(...){}
    
       @RequestMapping(method = RequestMethod.POST)
       public void post(...){}
    }
    or you can map individual methods with the full request path and method
    (if you don't specify a method both get and post will be accepted, can't remember about delete and put) e.g.,
    Code:
    @RequestMapping(value="/foo/bar.hm",method=RequestMethod.GET)
    public void getSomFoo(...){}
    hope that helps.

    Comment


    • #3
      It did, thank you. I also had to setup a bunch of other beans in xml context. But it now works and I was able to move forward with the tutorial.

      I hope the authors update the document soon.

      Comment


      • #4
        Originally posted by bmelloni View Post
        I hope the authors update the document soon.
        I agree and vote big time on updating the step-by-step tutorial ASAP. It's very difficult for a newcomer to try to learn Spring 3 MVC with annotations from the reference documentation. An updated tutorial would go a long way towards bringing us newbies up to speed and joining the ranks!

        Comment

        Working...
        X