Spring MVC - AlwaysUseFullPath configuration for annotation mappings

I am developing a Spring MVC application.

I am moving from the XML configuration of the controllers to the annotation-based configuration using @Controller and @RequestMapping to determine the URL mapping for the controllers.

I used to define 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 alwaysUseFullPath property as true for my url mappings. I want to set this property for annotation mappings ( @RequestMapping ), and I have two questions:

1) Can this be done based on class by class? for example, if I want some of my controllers to have this property, but some other controllers could not do this?

2) I saw that it can be installed by setting DefaultAnnotationHandlerMapping in XML and setting the hte property there (it looks like this will apply the property to all annotations), but I found this question - is it resolved now? or is this the only way around this to not use the string <mvc:annotation-driven> ?

thanks

+6
source share
1 answer

I'm not sure, but you mean something like this:

  @Bean(autowire = Autowire.BY_TYPE) public AnnotationMethodHandlerAdapter handlerAdapter(){ final AnnotationMethodHandlerAdapter annotationMethodHandlerAdapter = new AnnotationMethodHandlerAdapter(); annotationMethodHandlerAdapter.setAlwaysUseFullPath(true); return annotationMethodHandlerAdapter; } 
+1
source

Source: https://habr.com/ru/post/894623/


All Articles