ITeye博客

Spirng Exception :org.springframework.beans.NotWritablePropertyException

douh · 2010-11-04 10:53 · Spring · 企业架构 · Markdown

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


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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。