zoukankan      html  css  js  c++  java
  • Springboot2.0(Spring5.0)中个性化配置项目上的细节差异

      在一般的项目中,如果Spring Boot提供的Sping MVC不符合要求,则可以通过一个配置类(@Configuration)加上@EnableWebMvc注解来实现完全自己控制的MVC配置。但此时Springboot的@EnableAutoConfiguration自动设置就失效了,很多静态资源得不到自动映射,又很麻烦,不值当。
      而且,通常情况下,Spring Boot的自动配置是符合我们大多数需求的。如果想既需要保留Spring Boot提供的便利,又需要增加自己的额外的配置的时候,在Spring4及以下版本可以定义一个配置类并继承WebMvcConfigurerAdapter(它是一个抽象类),无需使用@EnableWebMvc注解。
       虽然继承WebMvcConfigurerAdapter这个类虽然有此便利,但在Spring5.0里面已经deprecated了。官方说明如下:
    WebMvcConfigurerAdapter Deprecated
    as of 5.0 WebMvcConfigurer has default methods (made possible by a Java 8 baseline) and can be implemented directly without the need for this adapter
      此时你也可以继承WebMvcConfigurationSupport类,但@EnableAutoConfiguration自动设置也会失效。
      官方文档也说了,WebMvcConfigurer接口现在已经有了默认的空白方法,所以在Springboot2.0(Spring5.0)下更好的做法还是implements WebMvcConfigurer。
     
     
    https://blog.csdn.net/fanpeizhong/article/details/79646681
  • 相关阅读:
    git this exceeds GitHub's file size limit of 100.00 MB
    使用vue-cli创建vue工程
    【转】Visual Studio Code必备插件
    linux安装openssl
    Centos7离线安装mysql8
    使用nmon来按频率采集数据
    Mac下编译android4.0.4遇到的问题
    32位ubuntu16.4编译android4.1.1
    vmvare安装vmtools菜单灰色
    Substrate 使用
  • 原文地址:https://www.cnblogs.com/softidea/p/8723011.html
Copyright © 2011-2022 走看看