tags:

views:

530

answers:

1

I am trying to use a MultiActionController in spring mvc, but I keep getting a 404 with the following message in the log

(org.springframework.web.servlet.PageNotFound) No mapping found for HTTP request with URI [/www.mysite.no/a/b/c] in DispatcherServlet with name 'myServlet'

It looks like I'm following the book example, but it still doesn't work? Ideas, anyone?

Code samples: web.xml

  <servlet-mapping>
    <servlet-name>subscriptionServlet</servlet-name>
    <url-pattern>/a/b/*</url-pattern>
  </servlet-mapping>

Spring config: my-servlet.xml

<beans ...>
  <bean id="myController" class="foo.bar.MyController">
    <property name="methodNameResolver" ref="productMethodNameResolver"/>
  </bean>

<bean id="productMethodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
    <property name="mappings">
      <value>
/*=view
      </value>
    </property>
  </bean>
</beans>

The controller:

public class MyController extends MultiActionController {

    Log logger = ...

    @Override
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception{

        logger.fatal("Never displayed in log");

        return super.handleRequest(request, response);
    }

    public ModelAndView view(HttpServletRequest request, HttpServletResponse response) throws Exception {
        logger.fatal("Never displayed in log");
        return null;
    }
+1  A: 

I had included url mapping to methods within the controller, but lacked url mapping to the actual controller. The following must be added to the spring config

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <value>
            /*=myController
        </value>
    </property>
</bean>
frankern