Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC - AlwaysUseFullPath configuration for annotation based mappings

I am developing a Spring MVC application.

I am moving away from XML configuration of the Controllers to annotation based config using @Controller and @RequestMapping to define the URL mapping to controllers.

Previously I defined the mappings in config as follows:

   <bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">        
        <property name="alwaysUseFullPath" value="true" />
        <property name="mappings">
            <props>
                <prop key="/status/**">statusController</prop>
            </props>
        </property>
    </bean>

You will see that I have defined the property alwaysUseFullPath as true for my url mappings. I want to set this property for the annotation mappings (@RequestMapping) and I have two questions:

1) Is it possible to do this on a class by class basis? e.g. if i want some of my controllers to have this property but some other controllers not to, is that possible?

2) I have seen that it can be set by configuring in XML the DefaultAnnotationHandlerMapping and setting hte property in there (looks like this will apply the property to all annotations) - but I have found this issue - is this resolved now? or is the only way to get around this to not use the <mvc:annotation-driven> line?

Thanks

like image 491
rhinds Avatar asked Aug 09 '11 10:08

rhinds


1 Answers

I am not sure but do you mean something like this :

 @Bean(autowire = Autowire.BY_TYPE)
    public AnnotationMethodHandlerAdapter handlerAdapter(){
    final AnnotationMethodHandlerAdapter annotationMethodHandlerAdapter = new AnnotationMethodHandlerAdapter();
    annotationMethodHandlerAdapter.setAlwaysUseFullPath(true);
    return annotationMethodHandlerAdapter;
    }
like image 62
sreeprasad Avatar answered Oct 27 '22 18:10

sreeprasad