๐ด The Error You're Seeing
Confirm this matches your console output. If it does, you're in the right place.
2026-02-14 20:30:11.500 ERROR 8842 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'userService' for bean class [com.devinhyderabad.service.UserServiceImpl] conflicts with existing, incompatible bean definition of same name and class [com.devinhyderabad.service.UserService]โก Quick Fix Works 80% of the time
Give one of the beans a distinct name in the @Service annotation.
@Service("userServiceImpl")
public class UserServiceImpl implements UserService { ... }๐ ๏ธ Solutions (3 Ways to Fix)
Explicitly name the beans
๐ Use this if you legitimately need two implementations of the same interface.
By default, Spring uses the lowercase class name as the bean name. If you have 'UserService' and 'UserServiceImpl', both register as 'userService'. Give them unique names.
@Service("primaryUserService")
public class UserServiceImpl implements UserService { ... }
@Service("secondaryUserService")
public class MockUserService implements UserService { ... }Delete the duplicate class
๐ Use this if you accidentally created two classes with the same name in different packages.
Sometimes developers copy-paste a class into a different folder. Spring sees both and gets confused. Delete the one you don't need.
// Ensure only one class is annotated with @Service
// for the 'UserService' functionality.Use @Primary or @Qualifier
๐ Use this when you have multiple beans of the same type and need to tell Spring which one to inject by default.
If you have multiple beans, annotate the main one with @Primary so Spring chooses it. Or use @Qualifier at the injection point.
@Service
@Primary // Spring will inject this one by default
public class UserServiceImpl implements UserService { ... }
// Or at injection point:
@Autowired
@Qualifier("secondaryUserService")
private UserService userService;๐ Version Notes
Allows bean overriding by default (spring.main.allow-bean-definition-overriding=true).
Bean overriding is disabled by default. Conflicting names cause immediate startup failure.
๐ง Why this Happens
Tap to expand the deep technical explanation
Spring scans your project and finds two different Java classes that are both trying to register themselves as a Spring Bean using the exact same name. Spring cannot decide which one to use, so it crashes.
The HITEC City Parking Spot Analogy:
It is like two employees in a company having the exact same email address. The mail server (Spring) doesn't know which inbox to deliver the message to, so it rejects the setup entirely.
๐ก๏ธ How to Prevent This Next Time
Stick to a strict naming convention. If you have an interface 'UserService', name the implementation 'UserServiceImpl' rather than 'UserService'.