@RequestMapping servlet not being found

615 Views Asked by At

I have a controller annotation defined like so :

@RequestMapping(value = "/myServlet" , method = RequestMethod.GET)
      public @ResponseBody String performAction() {
        return "success";
      }

This servlet is being invoked via an ajax request. But for some reason this request is not mapped. Its not being found when I attempt to navigate directly to the servlet via the URL. No errors are thrown. I'm just looking for some pointers on how to find out what my problem could be ?

4

There are 4 best solutions below

0
On BEST ANSWER

Did you add your controller to the dispatcher-servlet.xml (or whatever name you use for it) ?

At the very least, for each controller you should have something like

<bean name="contollerName"  class="package.ControllerName"/>
0
On

Have you put the annotation @Controller on top of your controller class where you have put this method for RequestMapping?

If yes then make sure you didn't forget to scan your controller package well in xml.

There are many guesses to your problem. Please put some more code for others to understand the problem well.

Hope this helps you.

Cheers.

0
On

if you are using annotations you should specify spring which packages it should scan

<context:component-scan base-package="your package" />
0
On

If you are using @configuration, be sure to scan the package where your controller is located :

@Configuration @ComponentScan(basePackages = "org.xxxx.web")