[英]DAO classes have the same @Qualifier
I have the source code of a website. 我有一个网站的源代码。
This website uses spring, and I'am confused about the Injection. 这个网站使用spring,我对注射感到困惑。
There are some DAO classes, on these DAO with a Qualifier : 有一些DAO类,在这些DAO上带有限定符:
@Repository("myDao")
@Qualifier("myTransactionManager")
public class MyCategoryDao {
}
But there is also another bean with the same name of the Qualifier. 但是,还有另一个与Qualifier名称相同的bean。
And this bean is a JpaTransactionManager. 这个bean是一个JpaTransactionManager。
@Configuration
@EnableTransactionManagement(mode = AdviceMode.PROXY)
@ComponentScan(basePackages = "com.my.repository")
public class DatabaseConfig {
@Primary
@Bean(name = "myTransactionManager")
public JpaTransactionManager jpaTransactionManager(
@Named("myEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
}
}
I don't know why the bean and the DAOs have the same name/Qualifier. 我不知道为什么bean和DAO具有相同的名称/限定符。
Wouldn't it conflict the others? 它不会与其他人冲突吗?
Spring will check for type first, and if there is any ambiguity, then only it will check for the name specified in @Qualifier. Spring将首先检查类型,如果有歧义,则只有它会检查@Qualifier中指定的名称。 In your case, types of both the beans are different, so that should work fine.
在您的情况下,两种bean的类型都不同,因此应该可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.