スプリングMVC設定(3):WebMvcConfiguratorインタフェース
3.WebMvcConfiguratorインタフェース
@EnableWebMvcが提供するカスタマイズ可能なインタフェースで、「D e l e g a tingWebMvcConfiguration.class」および「WebMvcConfigurationSupport.class」をカスタマイズできます.
@EnableWebMvc++implements WebMvcConfiguratorを使用すると、直接登録空よりも簡単に空にすることができます.
リファレンスインフラストラクチャ:SpringWeb MVC(白旗船)
@EnableWebMvcが提供するカスタマイズ可能なインタフェースで、「D e l e g a tingWebMvcConfiguration.class」および「WebMvcConfigurationSupport.class」をカスタマイズできます.
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp("/WEB-INF/", ".jsp");
}
}
@Configuration
@ComponentScan
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp("/WEB-INF/", ".jsp");
}
}
@Controller
public class HelloController {
@Autowired
HelloService helloService;
@GetMapping("/hello")
@ResponseBody
public String hello() {
return "Hello, " + helloService.getName();
}
@GetMapping("/sample")
public void sample(){
}
}
public class WebApplication implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(servletContext); // 추가
context.register(WebConfig.class);
context.refresh();
DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
ServletRegistration.Dynamic app = servletContext.addServlet("app", dispatcherServlet);
app.addMapping("/app/*");
}
}
これにより,@EnableWebMvc++implementWebMvcConfigurator+implementWebApplicationInitializer(DispatcherServiceRegistration)はSpringブートを使用せずにSpring MVCを使用することができる.@EnableWebMvc++implements WebMvcConfiguratorを使用すると、直接登録空よりも簡単に空にすることができます.
リファレンス
Reference
この問題について(スプリングMVC設定(3):WebMvcConfiguratorインタフェース), 我々は、より多くの情報をここで見つけました https://velog.io/@jsj3282/스프링-MVC-설정3-WebMvcConfigurer-인터페이스テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol