如果需要把application.properties配置中的一些配置内容,独立出来,我们可以使用PropertySource来读取单独的配置文件,仅支持properties类型,yml需要自己手动代码再实现
贴代码
person.java
package com.shrimpking.demo1;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
* Created by IntelliJ IDEA.
*
* @Author : Shrimpking
* @create 2023/12/22 11:27
*/
@Data
@Component
@PropertySource(value = "classpath:person.properties")
public class Person
{
@Value("${person.name}")
private String name;
@Value("${person.age}")
private Integer age;
@Value(("${person.boss}"))
private Boolean boss;
//不支持@value
private Map<String