当前位置: 首页 > news >正文

凡科网站制作平台抖音关键词排名优化软件

凡科网站制作平台,抖音关键词排名优化软件,江门网站优化快速排名,免费入驻的电商平台springboot扩展SpringMVC springboot为springmvc提供了很多自动配置#xff0c;虽然适用于大部分应用#xff0c;但是不一定适合你的应用 WebMvcConfigurer WebMvcConfigurer是用来全局定制化Spring boot的MVC特性#xff0c;可以通过实现WebMvcConfigurer接口来配置应用的M… springboot扩展SpringMVC springboot为springmvc提供了很多自动配置虽然适用于大部分应用但是不一定适合你的应用 WebMvcConfigurer WebMvcConfigurer是用来全局定制化Spring boot的MVC特性可以通过实现WebMvcConfigurer接口来配置应用的MVC全局特性但是由于该接口方法很多全部实现比较麻烦所以一般是继承WebMvcConfigurerAdapter类该类实现了WebMvcConfigurer接口并全部提供了空实现可以选择需要自定义的来进行重写的 WebMvcConfigurerAdapter类在springboot2.x中就不建议使用了因为java8中接口可以存在default方法使得WebMvcConfigurerAdapter没有意义直接实现WebMvcConfigurer接口即可 既保留自动配置又有扩展配置 根据官网的描述如果想要扩展SpringBoot对于SpringMVC的配置而又保留SpringBoot对SpringMVC的自动配置可以编写一个配置类Configuration继承WebMvcConfigurerAdapter类但是不能标注EnableWebMvc 如果是使用的springmvc框架而非springboot框架的话必须有EnableWebMvc注解否则重写WebMvcConfigurerAdapter的方法无效 Configurationpublic class MyMvcConfig extends WebMvcConfigurerAdapter {    // 配置拦截器    Override    public void addInterceptors(InterceptorRegistry registry) {        super.addInterceptors(registry);    }        // 时间、数字格式化    Override    public void addFormatters(FormatterRegistry registry) {    }        // 消息解析器   // 对应xml中的 mvc:annotation-driven    //    mvc:message-converters register-defaultstrue    //        bean classorg.springframework.http.converter.StringHttpMessageConverter    //            constructor-arg valueUTF-8/    //        /bean    //    /mvc:message-converters    ///mvc:annotation-driven    Override    public void configureMessageConverters(ListHttpMessageConverter? converters) {    }    // 验证器  用以处理所有注解了Valid的元素或注解了Validated 的控制器方法参数    Override    public Validator getValidator() {        return null;    }     // 静态资源过滤   // 对应xml 中的 mvc:resources location/WEB-INF/templates/ mapping/templates/**/   Override    public void addResourceHandlers(ResourceHandlerRegistry registry) {    }     // 视图解析器   // 对应于在xml中配置 viewResolver的bean   Override    public void configureViewResolvers(ViewResolverRegistry registry) {    }    } 原因 为什么继承WebMvcConfigurerAdapter就可以扩展springmvc的配置呢? 在WebMvcAutoConfiguration类中有一个bean是WebMvcAutoConfigurationAdapter  Configuration Import(EnableWebMvcConfiguration.class) EnableConfigurationProperties({ WebMvcProperties.class, ResourceProperties.class }) public static class WebMvcAutoConfigurationAdapter extends WebMvcConfigurerAdapter { 使用Import来引入的这个组件中有一个方法会将所有的WebMvcConfigurer类都加入到configurers中 public void setConfigurers(ListWebMvcConfigurer configurers) {  if (!CollectionUtils.isEmpty(configurers)) {   this.configurers.addWebMvcConfigurers(configurers);  } } 而WebMvcConfigurerAdapter就实现于WebMvcConfigurer public abstract class WebMvcConfigurerAdapter implements WebMvcConfigurer { 使用自定义配置抛弃自动配置 在上述配置类上加上EnableWebMvc注解就可以完全取代springboot对于springmvc的自动配置 原因 至于为什么会这样看一下EnableWebMvc这个注解就知道了 Retention(RetentionPolicy.RUNTIME)Target(ElementType.TYPE)DocumentedImport(DelegatingWebMvcConfiguration.class)public interface EnableWebMvc {} 这个注解会引入一个DelegatingWebMvcConfiguration组件而这个类是继承自WebMvcConfigurationSupport Configurationpublic class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport { 接下来看一下WebMvcAutoConfiguration的加载条件是什么 ConfigurationConditionalOnWebApplicationConditionalOnClass({ Servlet.class, DispatcherServlet.class,  WebMvcConfigurerAdapter.class })ConditionalOnMissingBean(WebMvcConfigurationSupport.class)AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE  10)AutoConfigureAfter({ DispatcherServletAutoConfiguration.class,  ValidationAutoConfiguration.class })public class WebMvcAutoConfiguration { ConditionalOnMissingBean(WebMvcConfigurationSupport.class) 可以看到是在没有WebMvcConfigurationSupport这个bean的时候才会加载所以打破了这个条件导致WebMvcAutoConfiguration不会生效 之前看到有人使用WebMvcConfigurationSupport来进行自定义配置这里也要注意一下如果使用了WebMvcConfigurationSupport的话WebMvcAutoConfiguration是不会生效的也就是说抛弃了webMvc的自动配置 https://zhhll.icu/2021/框架/springboot/基础/5.扩展SpringMVC/ 本文由 mdnice 多平台发布
http://www.zqtcl.cn/news/367793/

相关文章:

  • 知名网站建设加盟合作企业邮箱如何登录
  • asp net mvc做网站软文推广是什么
  • 张家口住房和城乡建设厅网站如何做点击赚钱的网站
  • 网站在建设中无法访问贵州碧江区住房和城乡建设局网站
  • 营销类网站 英文东莞正规的免费网站优化
  • 柳州网站推广最好的公司百度seo优化培训
  • 哈尔滨门户网站建站哪个网站做农产品
  • 网站行业关键词如何建设网站
  • wordpress插件目录504wordpress访问优化插件
  • 固定ip做网站网页源码提取工具
  • php网站模板源码下载公司网络营销推广软件
  • 免费电子版个人简历模板温州快速排名优化
  • 网站修改titlewordpress显示icp备案
  • 中国国际贸易单一窗口登录南京专业网站优化公司
  • 手机网站建设合同wordpress案例分析
  • 深圳做网站什么公司好广州电商小程序开发
  • 郑州高新区做网站的公司如何欣赏网站
  • 网站做维恩图做网站的公司杭州
  • 柳州公司网站制作公司wordpress 网店
  • 网站增加栏目费用在网站开发中如何设置登录
  • 怎样用php做网站百度推广联系人
  • 怎么建立手机网站如何申请公司域名
  • 营销型网站怎么收费邓州企业网站
  • 北京建设官方网站邢台网站维护
  • 新余网站制作网站开发工资咋样
  • 襄阳网站建设外包自己做一个网站
  • 网站域名的后缀wordpress文章归类
  • 查询企业信息的官方网站大连建设网站公司
  • 网站建设 全包专业建设规划方案模板
  • 做网站好还是做微信小程序好浙江建设工程造价信息网站