Bean属性“iUserGeneratorInterface”不可写或具有无效的setter方法(Bean property 'iUserGeneratorInterface' i

编程入门 行业动态 更新时间:2024-10-28 18:25:36
Bean属性“iUserGeneratorInterface”不可写或具有无效的setter方法(Bean property 'iUserGeneratorInterface' is not writable or has an invalid setter method)

我的项目结构如下 [1]: http : //i.stack.imgur.com/T1jvh.png

我有一个在create-user中定义的类和接口

UserGeneratorInterface

package com.credit.userGenerator; public interface UserGeneratorInterface { public String userIdGenerator(); }

RandomUserGenerator.java

public class RandomUserGenerator implements UserGeneratorInterface { public static enum Mode { ALPHA, ALPHANUMERIC, NUMERIC } public static String generateRandomString(int length, Mode mode) throws Exception { code logic } public String userIdGenerator(){ code logic } }

我已经在da-web中定义了应用程序上下文,并且想要获得RandomUserGenerator.java的服务

public class ApplicationSignManager implements IApplicationSignInterface { public UserGeneratorInterface iUserGeneratorInterface; public UserGeneratorInterface getiUserGeneratorInterface() { return iUserGeneratorInterface; } public void setiUserGeneratorInterface( UserGeneratorInterface iUserGeneratorInterface) { this.iUserGeneratorInterface = iUserGeneratorInterface; } }

AppContext.xml

<bean id="userGenerator" class="com.credit.userGenerator.RandomUserGenerator" ></bean> <bean id="appSign" class="com.*****.service.ApplicationSignManager"> <description>List of Dao in ApplicationLogin Manager</description> <property name="userGeneratorInterface" ref="userGenerator"/></bean>

但我得到以下例外

Bean属性“iUserGeneratorInterface”不可写或具有无效的setter方法。 setter的参数类型是否与getter的返回类型匹配?

I have a project structure as follows [1]: http://i.stack.imgur.com/T1jvh.png

I have a class and interface defined in create-user

UserGeneratorInterface

package com.credit.userGenerator; public interface UserGeneratorInterface { public String userIdGenerator(); }

RandomUserGenerator.java

public class RandomUserGenerator implements UserGeneratorInterface { public static enum Mode { ALPHA, ALPHANUMERIC, NUMERIC } public static String generateRandomString(int length, Mode mode) throws Exception { code logic } public String userIdGenerator(){ code logic } }

I have defined application context in da-web and wan to get service of RandomUserGenerator.java

public class ApplicationSignManager implements IApplicationSignInterface { public UserGeneratorInterface iUserGeneratorInterface; public UserGeneratorInterface getiUserGeneratorInterface() { return iUserGeneratorInterface; } public void setiUserGeneratorInterface( UserGeneratorInterface iUserGeneratorInterface) { this.iUserGeneratorInterface = iUserGeneratorInterface; } }

AppContext.xml

<bean id="userGenerator" class="com.credit.userGenerator.RandomUserGenerator" ></bean> <bean id="appSign" class="com.*****.service.ApplicationSignManager"> <description>List of Dao in ApplicationLogin Manager</description> <property name="userGeneratorInterface" ref="userGenerator"/></bean>

But I am getting the following exception

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

最满意答案

正如注释中所注意到的那样,使用带有大写“I”的setIUserGeneratorInterface()和getIUserGeneratorInterface()。 使用'property name =“iUserGeneratorInterface”ref =“userGenerator”' - 注意前导'i'。

请注意,在命名类和字段时始终建议使用完善的实践。 在您的情况下,将'UserGeneratorInterface'命名为'UserGenerator'并命名字段'iUserGeneratorInterface',只需'userGenerator'就会更有意义。 另请注意,您已将此字段声明为public(尽管这与错误无关)。

As noticed in the comments, use setIUserGeneratorInterface() and getIUserGeneratorInterface() with capital 'I'. Use 'property name="iUserGeneratorInterface" ref="userGenerator"' - note the leading 'i'.

Note that it is always advisable to use well-established practices when naming your classes and fields. In your case naming 'UserGeneratorInterface' simply 'UserGenerator' and naming the field 'iUserGeneratorInterface' simply 'userGenerator' would make more sense. Note also that you have declared this field public (although this has nothing to do with the errors).

更多推荐

本文发布于:2023-07-29 14:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1316707.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   方法   setter   iUserGeneratorInterface   Bean

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!