(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 ...
随机推荐
- DataBase -- Second Highest Salary
Question: Write a SQL query to get the second highest salary from the Employee table. +----+-------- ...
- LeetCode -- Merge Two Sorted Linked List
Question: Merge two sorted linked lists and return it as a new list. The new list should be made by ...
- 黑群晖DSM 6.1网卡支持列表
黑群晖DSM 6.1网卡支持列表 Network Drivers====================================AMDamd8111e : AMD 8111 (new PCI ...
- [POJ1784]Huffman's Greed
题面在这里 题意 给出一棵\(n\)个节点的二叉查找树的中序遍历中每个节点的访问次数\(p[i]\),和相邻两节点\(i\)和\(i+1\)的访问次数\(q[i]\),构造一棵二叉查找树使得\(\su ...
- Treap 模板
感觉平衡树也没有以前想的那么玄乎,(其实set超好用的),非旋式Treap挺好理解,和可并堆,二叉搜索树有很大联系 推荐博客:http://memphis.is-programmer.com/post ...
- 解决在极光推送的时候会出现一个 JPush提示:缺少统计代码
<span style="font-size:14px;"> @Override protected void onResume(){ super.onResume() ...
- hibernate连接oracle数据库
前言:以下所有的操作都是基于你已经成功安装了oracle数据库并且java的开发环境正常的情况下进行的. 如果没有完善请先配置基础环境. 第一步:配置需要的环境(下载并导入需要的包). 下载链接:ht ...
- windows mysql 安装及启动
0.下载:
- sphinx-python文档化
概述 下文讲述使用sphinx自动生成reStructuredText python API文档的简单过程. 配置流程 安装依赖 $ pip install sphinx blurb python-d ...
- 推荐下载App,如果本地安装则直接打开本地App(Android/IOS)
推荐下载App,如果本地安装则直接打开本地App(Android/IOS) - 纵观现在每家移动网站,打开首页的时候,都有各种各样的形式来提示你下载自身的移动App(Android/IOS),这是做移 ...