【发布时间】:2011-11-17 10:35:02
【问题描述】:
我现在有一个恼人的问题。 由于自动接线,我的测试失败了。
无法自动装配字段:private 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> {
}
CompanyDaoJpa
@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"/>
【问题讨论】:
-
其他 Spring XML 配置是什么样的?
标签: java spring-3 spring-test