You would have to add your implementation of HandlerMapping
and add it to list of handlers. You need to specify the order of handlers taking care of request as well:
@Bean
public SimpleUrlHandlerMapping simpleUrlHandlerMapping() {
SimpleUrlHandlerMapping simpleUrlHandlerMapping
= new SimpleUrlHandlerMapping();
Map<String, Object> urlMap = new HashMap<>();
urlMap.put("/**", defaultController());
simpleUrlHandlerMapping.setUrlMap(urlMap);
simpleUrlHandlerMapping.setOrder(1);
return simpleUrlHandlerMapping;
}
Here the defaultController()
method returns a @Controller
, that you have defined for the given mapping, so DefaultController
. The setOrder
method defines a priority (order) of handlers, starting from 0. Of course some default HandlerMapping
must be defined as a @Bean
as well. More about such configuration you can find here.
Edit with some thoughts from @Tobia:
You need to remove the @RequestMapping
annotation so that the controller is not picked up by RequestMappingHandlerMapping
and implement the AbstractController
interface to override the definition of controller in handleRequestInternal()
.