这是项目的结构:
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>
答案 0 :(得分:0)
问题是spring没有意识到他找不到文件类路径:** / applicationContext.xml,我预计在那种情况下会有文件找不到异常。
通过将其更改为file:../../../<explicit path>
,一切正常。