我想将application.properties中的值设置为application.properties中的employees,publicholidays和name字段。但是,在运行应用程序时,值不会注入到字段中。有没有人知道如何解决这个问题?
package hello.entities;
import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Value;
import java.util.*;
@Component
public class SessionShift{
String day;
String month;
String year;
@Value("#{'${my.list.of.employees}'.split(',')}")
private List<String> employees;
@Value("#{'${my.list.of.PH}'.split(',')}")
private List<String> publicholidays;
@Value("${my.name}")
private String name;
public List getEmployees(){
System.out.println("GETTING EMPLOYEES");
return this.employees;
}
public List getPublicholidays(){
System.out.println("GETTING PH");
return this.publicholidays;
}
public String getName(){
System.out.println("GETTING NAME");
return this.name;
}
public void setEmployees(List employees){
System.out.println("SETTING EMPLOYEES");
this.employees = employees;
}
public void setPublicholidays(List<String> publicholidays){
System.out.println("SETTING PH");
this.publicholidays = publicholidays;
}
public void setName(String name){
System.out.println("SETTING NAME");
this.name = name;
}
}
application.properties
myname = {name}
server.port=8186
error.whitelabel.enabled=false
my.list.of.employees=test1,test2
my.list.of.PH=08/04/2016
my.name = manish