java – 具有相同类名(不同包)的两个Spring Service Beans即使使
发布时间:2020-12-15 08:26:03 所属栏目:Java 来源:网络整理
导读:我有以下…… package package1;@Service@Qualifier("kb")public class UserService {...}package package2;@Service@Qualifier("user")public class UserService {...}@Autowired@Qualifier("user")package2.UserService p2;@Autowired@Qualifier("kb")pack
我有以下……
package package1; @Service @Qualifier("kb") public class UserService { ... } package package2; @Service @Qualifier("user") public class UserService { ... } @Autowired @Qualifier("user") package2.UserService p2; @Autowired @Qualifier("kb") package1.UserService p1; 但当我尝试运行时,我得到……
我如何拥有2个同名服务? 解决方法
从类中删除@Qualifier,仅在自动装配时使用@Qualifier
@Service("kb") public class UserService { ... } package package2; @Service("user") public class UserService { ... } 来自@Qualifier javadoc ** * This annotation may be used on a field or parameter as a qualifier for * candidate beans when autowiring. It may also be used to annotate other * custom annotations that can then in turn be used as qualifiers. */ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |