我现在有一个恼人的问题。由于自动接线,我的测试失败了。
无法自动装配字段:私有 k.dao.CompanyDao k.dao.CompanyDaoTest.companyDao;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有为依赖项找到类型为 [k.dao.CompanyDao] 的匹配 bean:预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者。
我认为@ContextConfiguration 可能是问题所在?
考试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:**/servlet-context.xml", "classpath:**/root-context.xml", "classpath:**/ccc-jpa.xml" })
public final class CompanyDaoTest {
@Autowired
private CompanyDao companyDao;
@Test
public void testTest() {
}
}
公司道
public interface CompanyDao extends GenericDao<Company> {
}
公司DaoJpa
@Repository("companyDao")
public class CompanyDaoJpa extends GenericDaoJpa<Company> implements CompanyDao {
public CompanyDaoJpa() {
super(Company.class);
}
}
通用道
public interface GenericDao<T extends DomainObject> {
public T get(Long id);
public List<T> getAll();
public T save(T object);
public T delete(T object);
}
servlet-context.xml
<annotation-driven />
<context:component-scan base-package="k"/>