Answer the question
In order to leave comments, you need to log in
How to configure DispatcherServlet correctly?
I'm trying to give a static html page support.html from the static folder. Found a variant using the MvcConfiguration configuration class. Without the configuration class, the logic involved in the rest of the controllers works, and when the application starts, index.html is returned. When adding a configuration, nothing works at all: "No mapping found for HTTP request with URI [/]". Is it possible to give support.html when requesting localhost:8080\view without creating xml files? How to properly configure the DispatcherServlet so that the project configuration that was previously working automatically is preserved? Is it correct to use @SpringBootApplication and additionally a config class?
Application class:
@SpringBootApplication
public class ApplicationMt {
public static void main(String[] args) {
SpringApplication.run(ApplicationM.class, args);
}
}
@RestController
public class Dispatcher {
@RequestMapping(value="/view" , method=RequestMethod.GET)
public ModelAndView redirectView(Locale locale, Model model) {
return new ModelAndView("support");
}
}
@Configuration
@ComponentScan(basePackages="com")
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter{
@Bean
public UrlBasedViewResolver getViewResolver(){
UrlBasedViewResolver resolver = new UrlBasedViewResolver ();
resolver.setPrefix("/static/");
resolver.setSuffix(".html");
resolver.setViewClass(JstlView.class);
return resolver;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question