在使用Sping进行开发应用时,需要配置的类中的属性是静态的,如果是通过IDE自动生成属性的setter和getter方法时,对应的方法也是static,那么通过property以来注入,就会报错:
比如:
以上情景的错误,只需要把setter 和getter方法声明中的static关键字去掉就可以。
org.springframework.beans.NotWritablePropertyException
比如:
public class IedHttpClientFactory {
// Map<intfName,iedHttpClient>
private static Map<String ,IedHttpClient> clientMap;
public static Map<String, IedHttpClient> getClientMap() {
return clientMap;
}
public static void setClientMap(Map<String, IedHttpClient> clientMap) {
IedHttpClientFactory.clientMap = clientMap;
}
public static IedHttpClient getIedHttpClient(String intfName) {
IedHttpClient client =clientMap.get(intfName);
if (client == null) {
throw new IedException("spring-ied.xml中未配置" + intfName
+ " 对应的IedHttpClient");
}
return client;
}
public static void destroy() {
for (Map.Entry<String,IedHttpClient> entry : clientMap.entrySet()) {
entry.getValue().destroy();
}
clientMap.clear();
}
public IedHttpClientFactory(){
}
}
以上情景的错误,只需要把setter 和getter方法声明中的static关键字去掉就可以。