Reputation: 10043
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
Upvotes: 7
Views: 3760
Reputation: 3260
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;
}
Upvotes: 1