簡體   English   中英

嘗試使用@Autowired時沒有類型的合格Bean

[英]No qualifying bean of type while trying to use @Autowired

這是項目的結構:

com
    ->services
        ->dal
            ->dao

這是類:

package com.services.dal.dao;
    @SuppressWarnings("unchecked")
    @Component
    public class PSDAO extends BaseDAO<ParkingSpots, ObjectId> implements IPSDAO{

    public PSDAO(Class<ParkingSpots> entityClass, MongoClient mongoClient, Morphia morphia,
            String datasource) {
        super(entityClass, mongoClient, morphia, datasource);
    }
}

接口:

package com.services.dal.dao;
public interface IPSDAO extends IBaseCRUD{

}

測試:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:**/applicationContext.xml")
public class PSDAOTest {

    @Autowired
    IPSDAO psDAO;
}

XML:

<bean class="com.services.dal.dao.PSDAO" id="PSDAO">
        <constructor-arg ref="morphia" index="0" />
        <constructor-arg ref="mongo" index="1" />
        <constructor-arg ref="mongoDb" index="2" />
</bean>

也在嘗試將其切換到:

<bean class="com.services.dal.dao.IPSDAO" id="PSDAO">
        <constructor-arg ref="morphia" index="0" />
        <constructor-arg ref="mongo" index="1" />
        <constructor-arg ref="mongoDb" index="2" />
</bean>

問題是spring無法識別他找不到文件classpath:** / applicationContext.xml,我希望在這種情況下會出現文件未找到異常。

通過將其更改為file:../../../<explicit path>一切正常。

暫無
暫無

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

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