无法实例化bean类:指定的类是一个接口 [英] Could not instantiate bean class: Specified class is an interface
问题描述
我知道有些线程与此问题类似.以下是我的课程,我正在spring.xml文件中对其进行配置.实际上,HumanResourceService是仅具有一种方法的接口.
I know there are threads similar to this issue. Below is my class and I am configuring it in spring.xml file. Actually HumanResourceService is an interface having only one method.
@Endpoint
public class HolidayEndpoint {
@Autowired
private HumanResourceService humanResourceService;
@Autowired
public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException {
this.humanResourceService = humanResourceService;
}
}
我的问题是在我的spring.xml文件中,当我将HumanResourceService定义为bean时,无法实例化它,因为这是一个接口.我该如何在spring配置文件中提到一个接口.我的spring.xml文件在下面
My problem is that in my spring.xml file, when I define HumanResourceService as bean, it cannot be instantiated as this is an interface. How can I mention an interface in spring configuration file. My spring.xml file is below
<bean id="holidayEndpoint" class="com.mycompany.hr.ws.HolidayEndpoint" autowire="constructor" >
<property name="humanResourceService" ref="humanResourceService" />
</bean>
<bean id="humanResourceService" class="com.mycompany.hr.service.HumanResourceService" />
推荐答案
您不能,Spring需要一些可以从中创建实例的东西,界面还不够.
You can't, Spring needs something it can make an instance from, the interface isn't enough.
在spring.xml中,具有id ="humanResourceService"的bean的class属性值应该是实现类的名称,而不是接口的名称. Spring需要您告诉它您要为此使用什么实现类.
In your spring.xml, the value of the class attribute for your bean with id="humanResourceService" should be the name of your implementation class, not the interface. Spring needs you to tell it what implementation class you want it to use for this.
这篇关于无法实例化bean类:指定的类是一个接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!