SpringBoot的springMVC自动配置(config)

一、以下是springboot对springMVC的默认配置

  • Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans.
    • 自动配置了ViewResolver(视图解析器:根据方法的返回值得到视图对象(View),视图对象决定如何
      渲染(转发?重定向?))
  • Support for serving static resources, including support for WebJars (see below).静态资源文件夹路
    径,webjars
  • Static index.html support静态首页访问
  • Custom Favicon support (see below). favicon.ico
  • 自动注册了 of Converter , GenericConverter , Formatter beans.
  • Support for HttpMessageConverters (see below)
    • Converter:转换器; public String hello(User user):类型转换使用Converter
    • Formatter 格式化器; 2017.12.17===Date;
  • Automatic registration of MessageCodesResolver (see below).定义错误代码生成规则
  • Automatic use of a ConfigurableWebBindingInitializer bean (see below).
    我们可以配置一个ConfigurableWebBindingInitializer来替换默认的;(添加到容器)

PS:以上默认配置都可以自己进行配置来替换修改

二、配置类(@Configuration)

既保留了所有的自动配置,也能用我们扩展的配置;

//使用WebMvcConfigurerAdapter可以来扩展SpringMVC的功能
@Configuration
public class MyMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
// super.addViewControllers(registry);
//浏览器发送 /atguigu 请求来到 success
registry.addViewController("/atguigu").setViewName("success");
}
}

PS:若添加了@EnableWebMvc,则删除所有的自动配置。只使用我们扩展的配置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值