I have the following...
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;
But when I try to run this I get...
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [boot.Application]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'userService' for bean class [package1.UserService] conflicts with existing, non-compatible bean definition of same name and class [package2.UserService]
How do I have 2 Services with the same name?
Remove @Qualifier from class, use @Qualifier while autowiring only
@Service("kb")
public class UserService {
...
}
package package2;
@Service("user")
public class UserService {
...
}
From @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.
*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With