读取指定文件和读取外部文件
@PropertySource读取指定文件
@PropertySource
加载指定的配置文件,只能用于properties文件。经测算对yml文件无效
在application.properties是全局配置文件,而我们在系统运行的时候可能会增加一些其他的配置,与Spring Boot无关的配置,不建议放在全局配置文件中,这就要用到@PropertySource
,@PropertySource
注解要配合@ConfigurationProperties
注解一起使用。
@PropertySource(value = {})
可以使用数组的形式,加载多个配置文件
实体:
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* @ClassName Person
* @Date 2019/7/11 16:57
* @Description
*/
@Component
@PropertySource(value = "classpath:person.properties")
@ConfigurationProperties(prefix = "person")
public class Person {
private String surname;
private String name;
private Integer age;
private Date birth;
private boolean boss;
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getName() {
return name;
}
public void setName(String name) {
this