尝试使用@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没有意识到他找不到文件类路径:**/applicationContext.xml,我预计在那种情况下会出现找不到文件的异常。
将它更改为 file:../../../<explicit path>
一切正常。
这是项目的结构:
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没有意识到他找不到文件类路径:**/applicationContext.xml,我预计在那种情况下会出现找不到文件的异常。
将它更改为 file:../../../<explicit path>
一切正常。