一.配置springboot webmvc
1.springboot webmvc配置方式
通过继承 extends WebMvcConfigurerAdapter
@Configuration
public class SpringMvcConfig extends WebMvcConfigurerAdapter {
通过 implements WebMvcConfigurer
@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {
使用@EnableWebMvc 禁用默认配置 所有配置自己重写
@Configuration
@EnableWebMvc
public class SpringMvcConfig extends WebMvcConfigurerAdapter {
2.springboot为springmvc提供了默认的配置 主要包括视图解析器、静态资源处理、类型转化器与格式化器、HTTP 消息转换器、静态主页的支持等。
3.EnableWebMvc注解问题
上面提到在使用 WebMvcConfigurer 扩展 Spring MVC 组件时,
类上不能加 @EnableWebMvc 注解,原因是在加上该注解后,Spring MVC 的自动配置会失效,
所有的东西都需要我们自动配置。
二.springboot webmvc配置讲解
1.参数详解
package com.spf.demo.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.*;
import java.util.List;
@Configuration
public class SpringMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
}
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
}
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
}
@Override
public void addFormatters(FormatterRegistry registry) {
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
}
@Override
public void addCorsMappings(CorsRegistry registry) {
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
}
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
}
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
}
@Override
public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> handlers) {
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
}
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
}
@Override
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {
}
@Override
public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {
}
}