果然还是不够细心啊,被坑一晚上..

一个极其简单的小程序,但是需要通过xml文件配置注入一个值,唯一的特别是要注入的属性是类中的静态成员变量..

如下,然后自动生成get和set方法..坑就从此开始了...

public class Food{
private static String desc; public static String getDesc(){
return desc;
} public static void setDesc(String desc){
Food.desc = desc;
}
}

然后xml中如下配置:

 <bean id="food" class="xxxk.Food" >
<property name="desc" value="食物" />
</bean>

然后启动就会报找不到set方法的错误...反复对比set方法的名字,无任何异常..然后一晚上就这样报废了...

最后发现自动生成的方法会带static修饰符,而spring的set方法不能是static的,跟一下源码能发现,虽然各种值和名字都能获取到,但是其中有一个resolvedDescriptor获取不到.

去掉set方法前面的static修饰符即可..

spring注入静态成员变量提示invalid setter method的更多相关文章

  1. Spring整合Hibernate报错:annotatedClasses is not writable or has an invalid setter method

    Spring 整合Hibernate时报错: org.springframework.beans.factory.BeanCreationException: Error creating bean ...

  2. 错误:Bean property 'sessionFactory' is not writable or has an invalid setter method.

    Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' ...

  3. is not writable or has an invalid setter method错误的解决

    java中在配置spring时,遇到is not writable or has an invalid setter method的错误一般是命名方式的问题 需要写成private userInfoD ...

  4. org.springframework.beans.NotWritablePropertyException:Bean property 'xxxService' is not writable or has an invalid setter method.

    完整报错提示信息:Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'blogDe ...

  5. Bean property ‘mapperHelper’ is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

    spring boot 报错: Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property ...

  6. Spring注入静态变量的方法,以及CXF如何获取客户端IP

    1.如果使用@Resource注解来注入静态变量的,服务器启动就会报错的.可以新增一个set方法,同时在set方法上用@Resource注解来注入. 2.或者直接在Spring的配置文件中使用< ...

  7. Spring 注入static变量

    一般我们我想注入一个static的变量,如下: @Autowired    private static String str; 不过,这样最终结果为null. 1.使用配置文件的方式注入 priva ...

  8. Bean property XX&#39; is not writable or has an invalid setter method

    刚刚搞spring.property注入时遇到这个问题,百度一下.非常多人说是命名或者get set方法不一致的问题,可是这个我是知道的.写的时候也注意到这些.所以应该不是这个问题.以为是xml头写的 ...

  9. [转]spring 注入静态变量

    原文: http://www.cnblogs.com/xing901022/p/4168124.html 今天碰到一个问题,我的一个工具类提供了几种静态方法,静态方法需要另外一个类的实例提供处理,因此 ...

随机推荐

  1. Python的sorted函数应用

    sorted()函数也是一个高阶函数,它还可以接收一个key函数来实现自定义的排序 L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88) ...

  2. 想要学好JQuery看这里

    一.简介 jQuery 库可以通过一行简单的标记被添加到网页中 jQuery 是一个 JavaScript 函数库. jQuery 库包含以下特性: HTML 元素选取 HTML 元素操作 CSS 操 ...

  3. liMarquee演示12种不同的无缝滚动效果

    很实用的一款liMarquee演示12种不同的无缝滚动效果 在线预览 下载地址 实例代码 <!DOCTYPE html> <html lang="zh-CN"&g ...

  4. asp.net C#发送邮件类

    很久前写的一个简单邮件发送类分享给大家: using System; using System.Data; using System.Configuration; using System.Web; ...

  5. Eclipse OSGi调试过程

    当你在开发的插件直接运行的时候,看起来正常的.但导出放到eclipse时候,又发觉不对劲,插件运行有问题.这个时候需要去OSGi的控制台调试插件,这一篇文章将讲述怎么简单调试eclipse插件(插件已 ...

  6. GitHub学习心得之 安装配置与多帐号管理

    作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 GitHub学习心得之 安装配置与多帐号管理 1.前言2.GitHub Linux安装(ub ...

  7. C/C++构建系统 -工具汇总

    关于构建系统可以先参考百科 http://en.wikipedia.org/wiki/List_of_build_automation_software http://www.drdobbs.com/ ...

  8. 一文让你彻底了解iOS字体相关知识

    写本文的契机主要是把自己整理的关于iOS字体方面的知识不断更新写在这篇博文中,用来自己以后查阅. 一.iOS原生字体展示 在label中选择字体的font,并把font由system改成custom后 ...

  9. OC点语法和变量作用域

    OC点语法和变量作用域 一.点语法 (一)认识点语法 声明一个Person类: #import <Foundation/Foundation.h> @interface Person : ...

  10. android 比较完善json请求格式

    public static String getHttpText(String url) { if (MyApplication.FOR_DEBUG) { Log.i(TAG, "[getH ...