zoukankan      html  css  js  c++  java
  • springboot框架笔记——springboot提供的自动配置

    Springboot基本配置

      spring MVC的定制配置需要我们的配置实现一个WebMvcConfigurer接口,如果实在spring环境下需要使用@EnableWebMVC注解,来开启对spring MVC的配置支持,这是我们就可以重写WebMvcConfigurer中的方法,完成我们的常用配置。

     1 /**
     2      * 设置允许跨域请求
     3      * @return
     4      */
     5     @Override
     6     public void addCorsMappings(CorsRegistry registry) {
     7         ConstantConfig config = context.getBean(ConstantConfig.class);
     8         Cors cors = config.getCors();
     9         registry.addMapping(cors.getMapping())
    10         .allowedOrigins(cors.getOrigins())
    11         .allowedMethods(cors.getMethods())
    12         .allowCredentials(cors.getCredentials()).maxAge(cors.getMaxAge());
    13         log.info(String.format("允许原域%s使用方法%S访问路径%s",
    14                 Arrays.toString(cors.getOrigins()),
    15                 Arrays.toString(cors.getMethods()),
    16                 cors.getMapping()));
    17     }
    18     
    19     
    20 
    21     @Override
    22     public void configurePathMatch(PathMatchConfigurer configurer) {
    23         configurer.setUseSuffixPatternMatch(false);// 在匹配路径的时候忽略后缀
    24     }
    25 
    26 
    27     // 添加静态资源访问路径
    28     @Override
    29     public void addResourceHandlers(ResourceHandlerRegistry registry) {
    30         // addResourceHandler指对外暴露的访问路径,addResourcesLocations指的是配置文件存放的目录
    31         registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/assets");
    32     }
    33     // 添加视图映射路径
    34     @Override
    35     public void addViewControllers(ViewControllerRegistry registry) {
    36         // 
    37         registry.addViewController("/").setViewName("index.html");
    38     }
  • 相关阅读:
    uglifyjs2压缩混淆js文件
    Html5应用程序缓存ApplicationCache
    nginx搭建笔记
    Free git private repo
    编程哲学之 C# 篇:007——如何创造万物
    编程哲学之 C# 篇:003——为什么选择 C#
    编程哲学之 C# 篇:004——安装 Visual Studio
    编程哲学之 C# 篇:006——什么是 .NET
    编程哲学之 C# 篇:005——"Hello,World!"
    为什么要使用Entity Framework
  • 原文地址:https://www.cnblogs.com/maosonglin/p/9828265.html
Copyright © 2011-2022 走看看