springboot框架笔记——springboot提供的自动配置
Springboot基本配置
spring MVC的定制配置需要我们的配置实现一个WebMvcConfigurer接口,如果实在spring环境下需要使用@EnableWebMVC注解,来开启对spring MVC的配置支持,这是我们就可以重写WebMvcConfigurer中的方法,完成我们的常用配置。
/**
* 设置允许跨域请求
* @return
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
ConstantConfig config = context.getBean(ConstantConfig.class);
Cors cors = config.getCors();
registry.addMapping(cors.getMapping())
.allowedOrigins(cors.getOrigins())
.allowedMethods(cors.getMethods())
.allowCredentials(cors.getCredentials()).maxAge(cors.getMaxAge());
log.info(String.format("允许原域%s使用方法%S访问路径%s",
Arrays.toString(cors.getOrigins()),
Arrays.toString(cors.getMethods()),
cors.getMapping()));
} @Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseSuffixPatternMatch(false);// 在匹配路径的时候忽略后缀
} // 添加静态资源访问路径
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// addResourceHandler指对外暴露的访问路径,addResourcesLocations指的是配置文件存放的目录
registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/assets");
}
// 添加视图映射路径
@Override
public void addViewControllers(ViewControllerRegistry registry) {
//
registry.addViewController("/").setViewName("index.html");
}
springboot框架笔记——springboot提供的自动配置的更多相关文章
- springboot入门之版本依赖和自动配置原理
前言 Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that ...
- springboot(十四)-分库分表-自动配置
上一节我们是手动配置数据源的,直接在java代码里写数据库的东西,这操作我个人是不喜欢的.我觉得这些东西就应该出现在application.yml文件中. 还有,万一我们的项目在使用之后,突然需要改变 ...
- springboot学习笔记-2 一些常用的配置以及整合mybatis
一.一些常用的配置 1.1 使用没有父POM的springboot 通过添加scope=import的依赖,仍然能获取到依赖管理的好处: <dependencyManagement> &l ...
- SpringBoot学习笔记(1):配置Mybatis
SpringBoot学习笔记(1):配置Mybatis 反思:如果自己写的笔记自己都看不懂,那就不要拿出来丢人现眼! IDEA插件 Free MyBatis Plugin插件可以让我们的MyBatis ...
- springboot 扫描不到包 @SpringBootApplication 自动配置原理
解决方案 在main类中增加注解 @ComponentScan("com.test.test.*") 扫描具体的包 @ComponentScan(basePackages = {& ...
- Springboot学习:底层依赖与自动配置的原理
springboot依赖的父项目 我们在创建springboot项目的时候,设置了一个父项目: 这个项目可以点进去,可以发现它依赖于另一个父项目 再次点进去,发现没有依赖父项目了 观察这个项目的pom ...
- 20、Springboot 与数据访问(JDBC/自动配置)
简介: 对于数据访问层,无论是SQL还是NOSQL,Spring Boot默认采用整合 Spring Data的方式进行统一处理,添加大量自动配置,屏蔽了很多设置.引入 各种xxxTemplate,x ...
- springboot 学习笔记(二)--- properties 配置
springboot可以提供了多种方式配置properties. 一.Java System.setProperty(k, v) System.setProperty("myname&quo ...
- SpringBoot学习笔记<一>入门与基本配置
毕业实习项目技术学习笔记 参考文献 学习视频 2小时学会Spring Boot:https://www.imooc.com/learn/767 学习资料 SpringBoot入门:https://bl ...
随机推荐
- 使用Mapping实现的以太坊智能合约的代码
Step 1: 创建一个基础合约 pragma solidity ^0.4.7; contract Coin { address public minter; mapping (address =&g ...
- Servlet学习(五)——通过response设置响应体及中文乱码问题
1.响应体设置文本 PrintWriter writer=response.getWriter(); 获得字符流,通过字符流的write(String s)方法可以将字符串设置到response 缓冲 ...
- 【原创】关于class.forname
连接数据库前都要调用一下class.forname("driverName");然后使用DriverMnager获取连接,这是为什么呢? 首先jdbc标准要求,每个驱动必须向Dri ...
- swift内存管理
为了解决引用循环的问题. However, with ARC, values are deallocated as soon as their last strong reference is rem ...
- SpringCloud学习笔记(20)----Spring Cloud Netflix之服务网关Zuul的各种姿势
1. 禁用过滤器 # zuul.<SimpleClassName>.<filterType>.disable=true # 例如禁用 自定义的过滤器 zuul.MyFilter ...
- vector ----- size函数注意事项
vector 的size函数返回vector大小,返回值类型为size_type,Member type size_type is an unsigned integral type,即无符号整数: ...
- vue v-if的使用
代码部分 <el-row> <el-col :span="20"> <template v-for="(node,i) of hierarc ...
- Postman(API & HTTP请求调试插件)
简述 Postman是一个Chrome扩展,提供功能强大的Web API & HTTP请求调试.它能够发送任何类型的HTTP 请求(GET.HEAD.POST.PUT..),附带任何数量的参数 ...
- Android基础笔记(十三)- 内容提供者原理和简单使用
为什么要有内容提供者 内容提供者的工作原理 使用内容解析者对内容提供者进行增删改查操作 利用内容提供者和内容解析者备份手机短信 利用内容提供者插入短信 为什么要有内容提供者 内容提供者技术的目的是: ...
- xcode5. 安装cocos2d-x 学习中。。。
找了一些帖子 没搞出来,后来找到原因了 如今的cocos2d版本号在xcode.5上 没右模版了. 用命令行 来运行.看了官方的文档.最终攻克了--- 对于自己解决的问题都会感到点兴奋. .. ...