我的项目结构如下 [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的返回类型匹配?
答案 0 :(得分:0)
请注意,在命名类和字段时,始终建议使用完善的实践。在您的情况下,将'UserGeneratorInterface'命名为'UserGenerator'并命名字段'iUserGeneratorInterface',只需'userGenerator'就会更有意义。另请注意,您已将此字段声明为public(尽管这与错误无关)。
答案 1 :(得分:0)
你的bean id =&#34; userGenerator&#34;
使用此&#34; userGenerator&#34;像(public UserGeneratorInterface userGenerator;)和变量名一样。
并为此变量创建getter,setter
然后尝试