tags:

views:

138

answers:

2

Hi,

I am trying to convert my app written in spring mvc 2.5 to use the annotated style of controller.

Apparently, I am unable to get things going. Hope somebody could help me here.

I have a mapping as below:

<li><a href="eqr/eqrItemList.htm"><span>Equipment Qual Report</span></a></li>

I created my controller like below:

@Controller
@RequestMapping("/eqr")
public class EQRMainController {
 private SimpleEQRTransManager eqrManager;
 protected final Log logger = LogFactory.getLog(getClass());

 @RequestMapping(value = "/eqrItemList.htm")
 public String setupForm(
   @RequestParam(value = "plant", required = false) String plant,
  return "eqrmain";
 }
}

I wanted to use the relative path so I set my request mapping at the class type level. But apparently, I am getting a 404 not found and a Handler mapping not found error at the tomcat console.

It says 'No mapping found for HTTP request with URI [/myapp/eqr/eqrItemList.htm]...'

I look at the firebug console and it is requesting below path:

http://localhost:8080/myapp/eqr/eqrItemList.htm

Dont really know why it cant find the mapping. Please help.

A: 

Check your servlet-mapping in web.xml:

     <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.do</url-pattern>
     </servlet-mapping>

If url-pattern fixes only some special extensions (like *.do in this example) then your servlet will never get this request.

Aleksey Otrubennikov
+1  A: 

Are you sure you've configured the context correctly for annotations?

In the MVC context configuration (typically called dispatcher-servlet.xml, depending on the name if your servlet) you can configure MVC annotation support quite simply using this element:

<mvc:annotation-driven />

This is the easiest way to tell Spring that you're going to use MVC annotations. Here's a snippet from one of my projects to put it into context:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;

<!-- Import my service beans -->
<import resource="application-context.xml" />

<mvc:annotation-driven />
<context:component-scan base-package="my.controllers.package.here" />

<!-- Other beans go here -->

Careful; this is Spring 3 so it may not fully apply for 2.5. Check the reference documentation (it explains this quite thoroughly).

pHk