这里记录一种spring boot读取配置文件的方式,不讨论@Value的方式了,那个太简单了
假设我们Yml中有配置:
##### 自定义队列信息
user:
mq:
log:
queue: logQueue
exchange: logExchange
routingKey: logRk
mail:
queue: mailQueue
exchange: mailExchange
routingKey: mailRk
新建已给类来接收
package com.wm.contextinit.config;
import lombok.Data;
import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import java.util.Map;
/***
* @ClassName: UserMqProperties
* @Description:
* @Author: wm_yu
* @Create_time: 14:12 2019-12-18
*/
@ConfigurationProperties("user.mq")
@Data
@ToString
public class UserMqProperties {
private Map<String,String> log;
private Map<String,String> mail;
@Bean("logMqProperties")
public MqProperties logMqPr