I use the following code to map the DispatcherServlet to / URL:
@Override protected String[] getServletMappings() { // TODO Auto-generated method stub return new String[] {"/"}; }
And I can visit my @Controller handler @Controller with the following URL:
http: // localhost: 8080 / MyWebApp / controller1 / method1
Then I changed the DispatcherServlet mapping below:
@Override protected String[] getServletMappings() { // TODO Auto-generated method stub return new String[] {"/app"}; //<=== HERE }
I was expecting the new URL below to work, but not really.
http: // localhost: 8080 / MyWebApp / application / controller1 / method1
He always gives me a 404 error.
I tried the following 2 ways to configure Controller , and it doesnโt work.
Option 1:
@Controller @RequestMapping("controller1") public class Controller1 { @RequestMapping("method1") public String Method1(Model model) { ... }
Option 2:
@Controller @RequestMapping("/app/controller1")
Why? How does getServletMappings() affect the final URL?
ADD 1
Itโs strange. If I write /app/* instead of just /app . It is working. But if so, how / to work at all? It should be /* if the logic is consistent.
But, as I tried, if I use /* , the servlet mechanism seems to be faulty, it could not even jsp page. Below I see in my browser. How can I show the source of a JSP page?
<% @page language = "java" contentType = "text / html; charset = ISO-8859-1" pageEncoding = "ISO-8859-1"%> ROOT: $ {root}!
WEB: $ {servlet}!
ADD 2
My WebMVC configuration:
@Configuration @EnableWebMvc @ComponentScan(basePackageClasses= {com.its.cloud.web.BeaconClassForComponentScan.class}) public class ITSCloudWebConfig extends WebMvcConfigurerAdapter { @Bean public ServletApplicationContextExplorer servletApplicationContextExplorer() { return new ServletApplicationContextExplorer(); } @Override public void configureDefaultServletHandling( DefaultServletHandlerConfigurer configurer) { configurer.enable(); } @Bean public UrlBasedViewResolver setupViewResolver() { UrlBasedViewResolver resolver = new UrlBasedViewResolver(); resolver.setPrefix("/views/"); resolver.setSuffix(".jsp"); resolver.setViewClass(JstlView.class); return resolver; } }
The structure of the package containing my controllers:

Using BeaconClassForComponentScan as the marker class for the @ComponentScan annotation, I believe that all scanned web , interfaces , impls and controllers pacakges will be scanned.
Link
Perhaps a related thread, but still does not fix the problem: Spring MVC configure url-pattern