Spring MVC - RequestMappingHandlerMapping Examples

Code Snippets Spring MVC 

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Controller
public class ExampleController {

@Autowired
private RequestMappingHandlerMapping mapping;

@RequestMapping("/example")
@ResponseBody
public String handle () {
System.out.println(mapping);
return "got it";
}
}




@Configuration
@ComponentScan
public class AppConfig extends WebMvcConfigurationSupport {

@Override
@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping () {
RequestMappingHandlerMapping m = super.requestMappingHandlerMapping();
m.setAlwaysUseFullPath(true);
return m;
}
}
Original Post




@Configuration
@ComponentScan
public class AppConfig extends WebMvcConfigurationSupport {
@Override
@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
RequestMappingHandlerMapping m = super.requestMappingHandlerMapping();
m.setDefaultHandler(new MyDefaultHandler());
return m;
}
}
Original Post




See Also