簡體   English   中英

無法實例化bean類:指定的類是一個接口

[英]Could not instantiate bean class: Specified class is an interface

我知道有類似於這個問題的線程。 下面是我的類,我在spring.xml文件中配置它。 實際上,HumanResourceService是一個只有一個方法的接口。

@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文件如下

<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需要它可以制作實例的東西,界面是不夠的。

在spring.xml中,id =“humanResourceService”的bean的class屬性值應該是實現類的名稱,而不是接口的名稱。 Spring需要您告訴它您希望它使用哪個實現類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM