java 方式配置spring mvc 继承WebMvcConfigurerAdapter和继承WebMvcConfigurationSupport
2017-08-30 09:54
471 查看
使用 java 的方式配置 sping mvc 时遇到一个疑问,在spring in action 这本书中 配置 mvc 时 采用 继承 WebMvcConfigurerAdapter 类
查阅网上其他资料时发现,其他大神也有采用继承自WebMvcConfigurationSupport 这个类。
顿时对这两个类产生疑问,对比发现
两个类都是来自包org.springframework.web.servlet.config.annotation
两个类都可以实现配置mvc。两者都可以配置视图解析器以及静态资源等
总结:
WebMvcConfigurationSupport 与WebMvcConfigurerAdapter 都可以配置MVC,WebMvcConfigurationSupport 支持的自定义的配置更多更全,WebMvcConfigurerAdapter有的WebMvcConfigurationSupport 都有
@Configuration @EnableWebMvc @ComponentScan( basePackages = Constants.MVC_PACKAGE_PATH, useDefaultFilters = false, includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = {Controller.class})} ) public class MvcConfig extends WebMvcConfigurerAdapter { private static final String VIEW_PREFIX = "/";// 视图前缀 private static final String VIEW_SUFFIX = ".jsp";// 视图后缀 private static final String VIEW_CONTENT_TYPE = "text/html;charset=UTF-8";//视图的内容类型。 /** * 配置 视图解析器 * @return */ @Bean public ViewResolver viewResolver(){ InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setCache(true); resolver.setPrefix(VIEW_PREFIX); resolver.setSuffix(VIEW_SUFFIX); resolver.setExposeContextBeansAsAttributes(true); resolver.setContentType(VIEW_CONTENT_TYPE); return resolver; } /** * 配置静态资源处理 * @param configurer */ @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { configurer.enable(); }
查阅网上其他资料时发现,其他大神也有采用继承自WebMvcConfigurationSupport 这个类。
@Configuration @EnableWebMvc @ComponentScan(basePackages = Constants.BASE_PACKAGE_PATH, useDefaultFilters = false, includeFilters = { @ComponentScan.Filter(type = FilterType.ANNOTATION, value = {Controller.class}) }) public class MvcConfig extends WebMvcConfigurationSupport { ... }
顿时对这两个类产生疑问,对比发现
两个类都是来自包org.springframework.web.servlet.config.annotation
两个类都可以实现配置mvc。两者都可以配置视图解析器以及静态资源等
总结:
WebMvcConfigurationSupport 与WebMvcConfigurerAdapter 都可以配置MVC,WebMvcConfigurationSupport 支持的自定义的配置更多更全,WebMvcConfigurerAdapter有的WebMvcConfigurationSupport 都有
相关文章推荐
- Spring MVC中WebMvcConfigurerAdapter、WebMvcConfigurationSupport与WebMvcConfigurer区别
- SpringMVC基于代码的配置方式(零配置,无web.xml)直接继承WebMvcConfigurerAdapter
- Spring MVC的WebMvcConfigurerAdapter:用bean代替xml配置并自定义配置
- Spring MVC的WebMvcConfigurerAdapter用法收集(零配置,无XML配置)
- 如何用Java类配置Spring MVC(不通过web.xml和XML方式)
- Spring Boot自定义MVC配置——WebMvcConfigurerAdapter
- 【springboot】之 解析@EnableWebMvc 、WebMvcConfigurationSupport和WebMvcConfigurationAdapter
- javaWeb项目SpringMVC3.2.1与Mybatis3.0.4整合实例(Mybaits-spring配置文件的几种方式)之一SqlSessionDaoSupport方式
- 【笔记】 Spring Boot [ 2 ] 之回顾 Spring MVC 的 WebMvcConfigurerAdapter 类
- spring mvc 的两种配置方式继承controller和xml配置delegate
- springBoot 使用继承WebMvcConfigurerAdapter 添加多个拦截器和继承HandlerInterceptorAdapter创建拦截器
- SpringBoot自定义序列化的使用方式--WebMvcConfigurationSupport
- Spring MVC的WebMvcConfigurerAdapter 作用
- 解析@EnableWebMvc 、WebMvcConfigurationSupport和WebMvcConfigurationAdapter
- springboot自定义springmvc配置的使用类WebMvcConfigurerAdapter
- 解析@EnableWebMvc 、WebMvcConfigurationSupport和WebMvcConfigurationAdapter
- spring mvc的拦截器WebMvcConfigurerAdapter
- xml零配置之WebMvcConfigurationSupport
- Spring Boot WebMvcConfigurerAdapter 实现拦截器无配置
- 如何用Java类配置Spring MVC(不通过web.xml和XML方式)