spring注入静态成员变量提示invalid setter method
果然还是不够细心啊,被坑一晚上..
一个极其简单的小程序,但是需要通过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的更多相关文章
- Spring整合Hibernate报错:annotatedClasses is not writable or has an invalid setter method
Spring 整合Hibernate时报错: org.springframework.beans.factory.BeanCreationException: Error creating bean ...
- 错误:Bean property 'sessionFactory' is not writable or has an invalid setter method.
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' ...
- is not writable or has an invalid setter method错误的解决
java中在配置spring时,遇到is not writable or has an invalid setter method的错误一般是命名方式的问题 需要写成private userInfoD ...
- 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 ...
- 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 ...
- Spring注入静态变量的方法,以及CXF如何获取客户端IP
1.如果使用@Resource注解来注入静态变量的,服务器启动就会报错的.可以新增一个set方法,同时在set方法上用@Resource注解来注入. 2.或者直接在Spring的配置文件中使用< ...
- Spring 注入static变量
一般我们我想注入一个static的变量,如下: @Autowired private static String str; 不过,这样最终结果为null. 1.使用配置文件的方式注入 priva ...
- Bean property XX' is not writable or has an invalid setter method
刚刚搞spring.property注入时遇到这个问题,百度一下.非常多人说是命名或者get set方法不一致的问题,可是这个我是知道的.写的时候也注意到这些.所以应该不是这个问题.以为是xml头写的 ...
- [转]spring 注入静态变量
原文: http://www.cnblogs.com/xing901022/p/4168124.html 今天碰到一个问题,我的一个工具类提供了几种静态方法,静态方法需要另外一个类的实例提供处理,因此 ...
随机推荐
- 管理系统-------------SSH框架书写登录和显示用户
一.思路的穿插. web.xml中的配置找到--->application.xml---->找到对应的Action---->找到struts.xml----->在去找actio ...
- MySQL 运行环境建议规范
一.操作系统环境 操作系统版本选择 CentOS/RHRL/ORACLE Linux 5.x/6.x x86_64 发行版 建议磁盘分区规则 MySQL 运行环境建议规范 挂载点 大小 分区类型 分区 ...
- 【循序渐进学Python】14.数据库的支持
纯文本只能够实现一些简单有限的功能.如果想要实现自动序列化,也可以使用 shelve 模块和 pickle 模块来实现.但是,如果想要自动的实现数据并发访问,以及更标准,更通用的数据库(databas ...
- C#如何用delegate实现Javascript的each方法
C#中有很多易混淆的关键词,例如delegate,Func, Action和 Predicate.Func, Action和 Predicate本质上都是delegate,下面看一下delegate概 ...
- github添加ssh key报错Key is invalid. Ensure you've copied the file correctly
github添加ssh key的时候报错:Key is invalid. Ensure you've copied the file correctly 将秘钥复制粘贴到文本编辑器中,再粘贴复制到
- Delphi 时间耗时统计
处理事情: 数据处理过程中,速度很慢,无法准确定位分析是DB问题还是客户端处理问题,所以增加计时统计日志: Delphi计时首次使用,查阅资料,予以记录: var BgPoint, EdPoind: ...
- abap--How to debug backgroud job
最近被一个朋友问起如何调试后台进程(一个abap的面试题),我一时也不知道如何答,他后来告诉我到sdn上找答案,我现在将答案收集供大家参考:Steps 1. Create variant called ...
- DevExpress应用案例--语音识别器Dual Writer
Dual Writer是 一个以语音识别为特色的文档处理器,无需安装其他软件,只需要插入你的麦克风就可以开始录入口述文字.它不仅支持MS Word的DOCX格式,还支持 RTF.ODT.TXT等常见文 ...
- android加固系列—2.加固前先要学会破解,调试内存值修改程序走向
[版权所有,转载请注明出处.出处:http://www.cnblogs.com/joey-hua/p/5138585.html] 因公司项目需要对app加固,经过本人数月的研究,实现了一套完整的仿第三 ...
- java 实现 LINQ 的一些框架记录一下
jOOQ: http://www.jooq.org JINQ: http://www.jinq.org JaQue: http://github.com/TrigerSoft/jaque JaQu: ...