无法实例化bean类:指定的类是一个接口

Vai*_*hav 9 spring

我知道有类似这个问题的线程.下面是我的类,我在spring.xml文件中配置它.实际上HumanResourceService是一个只有一个方法的接口.

@Endpoint
public class HolidayEndpoint {

    @Autowired
    private HumanResourceService humanResourceService;

    @Autowired
    public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException {
        this.humanResourceService = humanResourceService;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是在我的spring.xml文件中,当我将HumanResourceService定义为bean时,它无法实例化,因为这是一个接口.如何在spring配置文件中提及接口.我的spring.xml文件如下

<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" />
Run Code Online (Sandbox Code Playgroud)

Nat*_*hes 7

你不能,Spring需要它可以制作实例的东西,界面是不够的.

在spring.xml中,id ="humanResourceService"的bean的class属性值应该是实现类的名称,而不是接口的名称.Spring需要您告诉它您希望它使用哪个实现类.