Spring-boot(二)通过微信熟悉熟悉Spring-boot yml配置文件

第一种数组写法

find-list: [moments,Scan QR Code,Shake]

第二种数组写法

find-list:

  • moments

  • Scan QR Code

  • Shake

  1. yml的对象写法:“我”模块中包含着用户的昵称、头像、支付、相册等,可以当做一个对象来处理。

Spring-boot(二)通过微信熟悉熟悉Spring-boot yml配置文件

me:

wxNickName: .

wxId: miao90***

wxPay: payAdress

  1. 配置文件相关的两个注解

//将对象注入到容器内

@Component

//标注在类名上表示该类对应配置文件的“weixin

【一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义】

浏览器打开:qq.cn.hn/FTf 免费领取

@ConfigurationProperties(prefix = “weixin”)

总结: 以上四种yml的常用写法,除第一种很少能用上之外,其他的三种看似简单,但经常会因为空格层级关系不明确、实体类型映射不匹配等问题导致项目运行不成功!

附:测试相关代码

package com.wujianqinjian.springboot_note.bean;

import org.springframework.boot.context.properties.ConfigurationProperties;

import org.springframework.stereotype.Component;

import java.util.List;

import java.util.Map;

@Component

@ConfigurationProperties(prefix = “weixin”)

public class Weixin {

private List message;

private Map<String,String> contacts;

private List findList;

private Me me;

@Override

public String toString() {

return “Weixin{” +

“message=” + message +

“, contacts=” + contacts +

“, findList=” + findList +

“, me=” + me +

‘}’;

}

public List getMessage() {

return message;

}

public void setMessage(List message) {

this.message = message;

}

public Map<String, String> getContacts() {

return contacts;

}

public void setContacts(Map<String, String> contacts) {

this.contacts = contacts;

}

public List getFindList() {

return findList;

}

public void setFindList(List findList) {

this.findList = findList;

}

public Me getMe() {

return me;

}

public void setMe(Me me) {

this.me = me;

}

}

package com.wujianqinjian.springboot_note.bean;

import org.springframework.boot.context.properties.ConfigurationProperties;

import org.springframework.stereotype.Component;

@Component

@ConfigurationProperties(prefix = “contacts”)

public class Contacts {

private String imageUrl;

private String nickName;

@Override

public String toString() {

return “Contacts{” +

“imageUrl=’” + imageUrl + ‘’’ +

“, nickName=’” + nickName + ‘’’ +

‘}’;

}

public String getNickName() {

return nickName;

}

public void setNickName(String nickName) {

this.nickName = nickName;

}

public String getImageUrl() {

return imageUrl;

}

public void setImageUrl(String imageUrl) {

this.imageUrl = imageUrl;

}

}

package com.wujianqinjian.springboot_note.bean;

import org.springframework.boot.context.properties.ConfigurationProperties;

import org.springframework.stereotype.Component;

@Component

@ConfigurationProperties(prefix = “me”)

public class Me {

private String wxNickName;

private String wxId;

private String wxPay;

private String wxCollect;

private String wxPhoto;

private String wxCards;

private String wxExpression;

@Override

public String toString() {

return “Me{” +

“wxNickName=’” + wxNickName + ‘’’ +

上一篇:五个改善你服务器日志的技术


下一篇:CentOS4.4下邮件服务器架设笔记之windows AD整合功能实现