/* This condition will ariese when we will read the values from property file and there a change to use this value in static area */
@Component
public class Employee{
String name="radhe";
}
public class Address{
@Autowired
Employee employee;
public static void display(){
employee.name;
}
}
试试这个。
1.构造函数注入
public class Address{
private static Employee employee;
@Autowired
public Address(Employee employee){
Address.employee= employee;
}
public static void display(){
employee.name;
}
}
2.后构造
public class Address{
private static Employee employee;
@Autowired
private Employee employeeI;
@PostConstruct
public void init() {
Address.employee= employeeI;
}
public static void display(){
employee.name;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句