1.先写一个类,例如下 有两个属性 socket msg,并且都是boolean类型
@Component // 或者在启动类加@EnableConfigurationProperties({SendSocketMsgProperties.class})
@ConfigurationProperties(prefix = "com.test.send")
public class SendSocketMsgProperties {
private boolean socket;
private boolean msg;
public boolean isSocket() {
return socket;
}
public void setSocket(boolean socket) {
this.socket = socket;
}
public boolean isMsg() {
return msg;
}
public void setMsg(boolean msg) {
this.msg = msg;
}
}
2. yml配置文件写法如下
3. 使用
@Autowired
SendSocketMsgProperties properties;
这样就可以使用啦