Question

I thought ControllerClassNameHandlerMapping was for mapping a url to a controller (after removing the Controller portion) but this doesnt seem to be the case with my example.

If I remove the "/navigation" mapping from the navigation controller (see below) then I get 404 errors.

<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />

<bean name="navigationController" class="com.mvc.controller.NavigationController">
    <property name="methodNameResolver">
        <bean class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
            <property name="mappings">
                <props>
                   <prop key="/navigation/menu">menuHandler</prop>
                </props>
           </property>
        </bean>
    </property>
</bean>

In the code snippet above I need to pass the property key as /navigation/menu but I thought if the /navigation is mapped to the controller then I could get away with passing /menu otherwise what is the point of the ControllerClassNameHandlerMapping?

I tried removing ControllerClassNameHandlerMapping but it is needed.

Can somebody explain what the ControllerClassNameHandlerMapping is actually doing?

Thanks

Was it helpful?

Solution

The ControllerClassNameHandlerMapping is mapping:

/navigation/* -> NavigationController.

If you remove it, the NavigationController is never executed and lost any chances to map the url to a method.

The workflow is:

 DispatcherServlet -> ControllerClassNameHandlerMapping 
 -> NavigationController -> MethodNameResolver -> method

Edit

For example if you want to map "menu" directy to menuHandler method you could use the following MethodNameResolver

public class LastPathNameMethodResolver extends AbstractUrlMethodNameResolver {

    private Properties mappings;

    @Override
    protected String getHandlerMethodNameForUrlPath(String urlPath) {
        return mappings.getProperty(StringUtils.substringAfterLast(urlPath, "/"));
    }

    public Properties getMappings() {
        return mappings;
    }

    public void setMappings(Properties mappings) {
        this.mappings = mappings;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top