---
title: "Spirng Exception :org.springframework.beans.NotWritablePropertyException"
author: "douh"
date: "2010-11-04T10:53:16Z"
tags: []
categories: ["企业架构"]
slug: "spirng-exception-org-springframework-beans-notwritablepropertyexception"
draft: false
lastmod: "2010-11-04T10:53:16Z"
id: 802508
url: "https://douh.iteye.com/blog/802508"
---

在使用Sping进行开发应用时，需要配置的类中的属性是静态的，如果是通过IDE自动生成属性的setter和getter方法时，对应的方法也是static，那么通过property以来注入，就会报错：
```java

org.springframework.beans.NotWritablePropertyException

```

比如：

```java

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关键字去掉就可以。