Code example for RequestMappingHandlerMapping

Methods: setContentNegotiationManagersetUseRegisteredSuffixPatternMatchsetUseSuffixPatternMatchsetUseTrailingSlashMatch, setInterceptors, setOrder, setPathMatcher, setUrlPathHelper

0
    @Bean 
    @Override 
    public RequestMappingHandlerMapping requestMappingHandlerMapping() { 
        RequestMappingHandlerMapping result = super.requestMappingHandlerMapping(); 
        result.setUseSuffixPatternMatch(false); 
        result.setUseTrailingSlashMatch(false); 
        return result; 
    } 
 
    @Override 
    protected void addResourceHandlers(ResourceHandlerRegistry registry) { 
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/").setCachePeriod(31556926); 
    } 
 
    @Bean 
    public ContentNegotiatingViewResolver contentNegotiatingViewResolver() { 
        ContentNegotiatingViewResolver result = new ContentNegotiatingViewResolver(); 
        Map<String, String> mediaTypes = new HashMap<String, String>(); 
        mediaTypes.put("json", MediaType.APPLICATION_JSON_VALUE); 
        result.setMediaTypes(mediaTypes); 
        MappingJacksonJsonView jacksonView = new MappingJacksonJsonView(); 
        jacksonView.setExtractValueFromSingleKeyModel(true); 
        Set<String> modelKeys = new HashSet<String>(); 
        modelKeys.add("events"); 
        modelKeys.add("event"); 
        jacksonView.setModelKeys(modelKeys); 
        result.setDefaultViews(Collections.singletonList((View) jacksonView)); 
        return result; 
    } 
 
    @Bean 
    public InternalResourceViewResolver internalResolver() { 
        InternalResourceViewResolver internalResolver = new InternalResourceViewResolver(); 
        internalResolver.setPrefix("/WEB-INF/views/"); 
        internalResolver.setSuffix(".jsp"); 
        return internalResolver; 
    } 
 
    @Override 
    public void addViewControllers(ViewControllerRegistry registry) { 
        super.addViewControllers(registry); 
        registry.addViewController("/login/form") 
                .setViewName("login"); 
        registry.addViewController("/errors/403") 
                .setViewName("/errors/403"); 
    } 
}