Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

## Spring 学习笔记

[TOC]

### 配置文件

1. ##### 【配置文件】spring.profiles 的 active 与 include 区别

active:【多选】要加载的 profile;一般为一个,包含全部配置信息;用于切换当前全部配置上下文,如:
dev,prod,test 等

include:【多选】还要加载的 profile,一般为多个,包含部分配置信息,用于将配置信息拆分到不同的
文件中,降低耦合,可自由组合;

2. ##### 【配置文件】多语言支持 spring.messages

spring.messages.basename:指定基本多语言文本配置文件的路径,如:i18n/messages,内容通过
键值对进行定义,如:

```
#错误消息
not.null=* 必须填写
user.password.retry.limit.count=密码输入错误{0}次
```

其中通过{0}占位符,占位符中的数字代表参数的顺序

spring.messages.local:指定默认的语言及区域,如:“en_US”,“zh_CN”

根据区域语言寻找多语言配置文件的过程为:【spring.messages.basename】+
【spring.messages.local】.properties

通过 MessageSource 进行调用

```java
@Autowired
private MessageSource messageSource;

@GetMapping("/hello")
public String hello(@RequestParam(name = "name", required = false) String name,
Locale locale) {
String message = messageSource.getMessage("hello.message", new Object[]
{name}, locale);
return message;
}
```

3.

4.

5.
6.

7. 23

8. 4

------

### 日志

1. 日志级别及顺序

trace<debug<info<warn<error<fatal

2.

3.

4.

5.

6. 2

You might also like