玩转springboot入门配置yml单元测试文件获取值
生活随笔
收集整理的這篇文章主要介紹了
玩转springboot入门配置yml单元测试文件获取值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一 . 創建application.yml文件
server:port: 8081 # 運行端口#值得寫法 將在實體類中使用到 persion:name: 測試名稱age : 99pets: #數組- cat- dog- pigfriends: #對象name: 張三age : 20二 創建 persion實體類 設置set方法
package com.sd.vo;import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;import java.util.List; import java.util.Map; @Component //加到容器中 @ConfigurationProperties(prefix ="persion") //告訴springboot與配置文件中的哪個屬性進行映射 public class Persion{private String name;private Integer age;private List<Object> pets;private Map<String,Object> friends;@Overridepublic String toString() {return "Hello{" +"name='" + name + '\'' +", age=" + age +", pets=" + pets +", friends=" + friends +'}';}public void setName(String name) {this.name = name;}public void setAge(Integer age) {this.age = age;}public void setPets(List<Object> pets) {this.pets = pets;}public void setFriends(Map<String, Object> friends) {this.friends = friends;} }
報這個錯需要加入
配置文件處理器
三 單元測試啟動類
五 控制體運行 測試類
總結
以上是生活随笔為你收集整理的玩转springboot入门配置yml单元测试文件获取值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 宝塔面板使用阿里云ssl证书
- 下一篇: @ConfigurationProper