![](/img/trans.png)
[英]Autowire annotation driven bean into bean specified in Java config with constructor injection
[英]Autowire Bean with no default constructor, using config annotation
我有这个Repository类,希望在单元测试中自动连线。 我目前在运行测试时遇到“没有默认构造函数”错误。
有问题的类没有默认的构造函数,我是spring的新手,所以可能没有在config类中正确创建Bean。
以下是有问题的Bean(没有默认构造函数)
@Repository
public class GenericDaoImpl<T extends AbstractEntity> implements GenericDao<T> {
配置类
@Configuration
@EnableAspectJAutoProxy
@ComponentScan(basePackages = "com.example")
public class AppConfig {
@Bean
GenericDaoImpl<AbstractEntity> genericDoaIpm(final Class<AbstractEntity> tClass) {
return new GenericDaoImpl<AbstractEntity>(tClass);
}
}
在测试中,我有:
@Autowired
private GenericDaoImpl<AbstractEntity> genericDaoImpl;
我有什么想念的地方吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.