Does the parameter type of the setter match the return type of the getter?

在添加spring配置文件的时候我遇到的一个问题 

Bean property 'targetObject' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

是在注入成员变量的时候出了问题 经过在网上查找资料总结了一下2个问题

1、变量名 命名不规范 因为Spring要求注入的成员变量要按照Sun的命名规范。

2、参数名书写错误。

但是我就不一样了 ,我和他们的错误方式都不一样  ,让后我打开了bean 后边的class的源文件查看 发现这个貌似不是我要的那个class文件  ,果然 我的class文件写错了  没有这个根本参数。快被自己蠢哭了 ,花了一个小时的时间。

所以总结一下 如果遇到开头提到的那个问题,可以按照以下顺序解决。

1、查看自己需要注入的bean 的class 有没有问题

就是这个位置的东西;

2、查看自己注入的参数名写没写错大小写注意 ;

就是这;

3、有的参数是bean 的 参数名不仅要写对还要按照Sun的命名规范命名

就是这儿了;

好吧就这么多了,

猜你喜欢

转载自blog.csdn.net/liu123342/article/details/81252138