![](/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.