ymal的使用

dog:
name: 旺财
age: 123

文件的注释
package com.song.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "dog")
@Component
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Dog {

private String name;
private Integer age;
}


测试类

package com.song.demo1;

import com.song.pojo.Dog;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class Demo1ApplicationTests {
@Autowired
private Dog dog;
@Test
void contextLoads() {
System.out.println(dog);
}

}
posted @ 2022-07-01 08:52  小松2739  阅读(36)  评论(0编辑  收藏  举报