@Component
@PropertySources(
{@PropertySource(value={"classpath:Pro.properties"},encoding="utf-8"),
@PropertySource(value={"classpath:Pro1.properties"},encoding="utf-8")}
)
public class Dog {
@Value("${dog.name}")
private String name;
@Value("${dog.age}")
private int age;
@Override
public String toString() {
return "name=="+this.name+" age=="+this.age;
}
}
public class Test {
public static void main(String[] args) {
AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext("com.edu.property");
Dog dog = annotationConfigApplicationContext.getBean(Dog.class);
System.out.println(dog);
}
}