(2)SpringBoot 配置
一、SpringBoot全局配置文件
SpringBoot两个全局配置文件,application.properties和application.yml

例如端口号配置
(1)application.properties文件

(2)application.yml文件格式

二、yaml文件格式语法
1.大小写敏感
2.属性: 值 之间必须有空格
3.值如果是字符串 默认不用加引号。加单引号转义字符功能失效原样输出,加双引号转义字符有转义功能,
4.对象
(1)

(2)或者

5.

三、调用yaml
1.pom.xml添加
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
2.

package com.example.demo.bean; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component; @Component
@ConfigurationProperties(prefix = "person")
public class Person {
private String name;
private int age; public String getName() {
return name;
}
public void setName(String username) {
this.name = username;
}
}
单元测试

package com.example.demo; import com.example.demo.bean.Person;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests { @Autowired //
Person person; @Test
public void contextLoads() {
System.out.println(person.getName());
}
}
测试文件运行

四、application.properties配置
书写方式

运行同理
注意如果是有中文

properties文件 需要转成ascii

六、用value注解方式单个读取配置文件


七、 加载非全局配置文件
创建一个

@Component
@ConfigurationProperties(prefix = "person")
@PropertySource(value = {"classpath:person.properties"})
public class Person {
private String name; public String getName() {
return name;
}
public void setName(String username) {
this.name = username;
}
}
八、导入Spring 配置文件

九、占位符

十、激活指定profile
快速切换开发、测试、生产的配置环境
1. properties的激活

一个开发环境,一个生产环境的配置文件
在application.properties 中激活开发环境的配置

2.yml的激活


3.命令行方式激活


4.虚拟机参数

十一、配置顺序
1.

2.外部加载配置

(2)SpringBoot 配置的更多相关文章
- SpringBoot配置属性之Server
SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...
- SpringBoot基础系列-SpringBoot配置
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9990680.html SpringBoot基础系列-SpringBoot配置 概述 属性 ...
- springboot上传文件 & 不配置虚拟路径访问服务器图片 & springboot配置日期的格式化方式 & Springboot配置日期转换器
1. Springboot上传文件 springboot的文件上传不用配置拦截器,其上传方法与SpringMVC一样 @RequestMapping("/uploadPicture&q ...
- springboot配置Druid数据源
springboot配置druid数据源 Author:SimpleWu springboot整合篇 前言 对于数据访问层,无论是Sql还是NoSql,SpringBoot默认采用整合SpringDa ...
- springboot配置详解
springboot配置详解 Author:SimpleWu properteis文件属性参考大全 springboot默认加载配置 SpringBoot使用两种全局的配置文件,全局配置文件可以对一些 ...
- SpringBoot 配置 Servlet、Filter、Listener
SpringBoot 配置 Servlet.Filter.Listener 在SpringBoot应用中,嵌入式的 Servlet 3.0+ 容器不会直接使用 ServletContainerInit ...
- SpringBoot 配置静态资源映射
SpringBoot 配置静态资源映射 (嵌入式servlet容器)先决知识 request.getSession().getServletContext().getRealPath("/& ...
- springboot配置server相关配置&整合模板引擎Freemarker、thymeleaf&thymeleaf基本用法&thymeleaf 获取项目路径 contextPath 与取session中信息
1.Springboot配置server相关配置(包括默认tomcat的相关配置) 下面的配置也都是模板,需要的时候在application.properties配置即可 ############## ...
- springboot配置cxf
1.引入两个需要的jar <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf- ...
- SpringBoot配置(2) slf4j&logback
SpringBoot配置(2) slf4j&logback 一.SpringBoot的日志使用 全局常规设置(格式.路径.级别) SpringBoot能自动适配所有的日志,而且底层使用slf4 ...
随机推荐
- SCU3037 Painting the Balls
Description Petya puts the \(N\) white balls in a line and now he wants to paint some of them in bla ...
- NEYC 2017 游记
day 1: result: sum_rank: 11 school_rank:1 水题在你高估的时候就已经不水了 sum:有个快速乘类似快速幂: int ans=0; ...
- [hdu 2586]lca模板题(在线+离线两种版本)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2586 在线版本: 在线方法的思路很简单,就是倍增.一遍dfs得到每个节点的父亲,以及每个点的深度.然后 ...
- hdu 3473 (划分树)2
Minimum Sum Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- Virtualization solutions on Linux systems - KVM and VirtualBox
Introduction Virtualization packages are means for users to run various operating systems without &q ...
- js 内置对象属性及方法
1.Date 属性(1): constructor 所建立对象的函数参考 prototype 能够为对象加入的属性和方法 方法(43): getDay() 返回一周 ...
- css属性选择器应用
代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3. ...
- css之postion定位
css position之初识 我们先看看position定位有那几个属性,下面是我从w3c的截图,为我们认识定位做初步的了解 通过上面这张图嘞,我们知道了position有5个属性,那么下面,我就来 ...
- 转:LVS负载均衡
1.什么是LVS? 首 先简单介绍一下LVS (Linux Virtual Server)到底是什么东西,其实它是一种集群(Cluster)技术,采用IP负载均衡技术和 基于内容请求分发技术.调度器具 ...
- 3中转换JSON数据的方式
一:前言 来公司一个星期,把最近做的东西梳理下,并把觉得有必要的知识点记载下,现在传数据很多都是用JSON来传数据,所以我就找了集中传json的方式,其实是有五种的,但是有一个我没有用过,太陌生了,上 ...