我有一个如下定义的类
0x31
public class Caller {
private GreetingService greetingService;
private String name;
public Caller(GreetingService greetingService) {
System.out.println("Inside the constructor of Caller");
this.greetingService = greetingService;
}
public void invokeGreet(String message) {
greetingService.greet(message, "Pradeep");
}
public void myCustomInit() {
System.out.println("Came inside the custom initializer method");
}
public void myCustomDestroy() {
System.out.println("Came inside the custom destroy function..");
}
}
是一个接口
GreetingService
AwesomeGreet类:
public interface GreetingService {
public void greet(String message, String name);
}
我的public class AwesomeGreet implements GreetingService {
private String salutation;
public String getSalutation() {
return salutation;
}
public void setSalutation(String salutation) {
this.salutation = salutation;
}
public void greet(String message, String name) {
System.out.println("Hello !! "+salutation+" " +name +" "+message);
}
}
文件如下所示:
application-context.xml
当我尝试加载<bean id="caller" class="com.classpath.spring.Caller" scope="prototype">
<constructor-arg name="greetingService"
ref="awesomeGreet" />
</bean>
<bean id="awesomeGreet" class="com.classpath.spring.AwesomeGreet" scope="prototype">
<property name="salutation" value="Mr"></property>
</bean>
时,出现以下错误:
application-context
我不确定,我要去哪里错了。将范围设置为Singleton时,相同的示例可以正常工作。
答案 0 :(得分:0)
我认为,bean定义应具有class="com.classpath.spring.GreetingService"