Spring如何value注入List
第一种:使用Spring EL:
my.list.of.strings=ABC,CDE,EFG
@Value("#{'${my.list.of.strings}'.split(',')}")
private List<String> myList;
第二种
email.sendTo[0]=somebody@example.com
email.sendTo[1]=somebody2@example.com
email.sendTo[2]=somebody3@example.com
@Component
@ConfigurationProperties("email")
public class EmailProperties {
private List<String> sendTo;
public List<String> getSendTo() {
return sendTo;
}
public void setSendTo(List<String> sendTo) {
this.sendTo = sendTo;
}
}
Loading...