๐Ÿ”ด The Error You're Seeing

Confirm this matches your console output. If it does, you're in the right place.

ERROR LOGError starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2023-10-25 10:15:30.812 ERROR 12345 --- [ main] o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.devinhyderabad.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.springframework.beans.factory.support.SimpleConstructorResolver.instantiate(SimpleConstructorResolver.java:172)

โšก Quick Fix Works 80% of the time

Add @Service or @Component to the class you are trying to inject.

@Service public class UserServiceImpl implements UserService { ... }

๐Ÿ› ๏ธ Solutions (3 Ways to Fix)

Solution 1โœ“ Most common cause

Add a stereotype annotation to the class

๐Ÿ‘‰ Use this when you wrote the class yourself but forgot to tell Spring to manage it.

Annotate the class with @Service, @Component, or @Repository so Spring picks it up during component scanning.

@Service public class UserServiceImpl implements UserService { ... }
Solution 2

Fix the ComponentScan base package

๐Ÿ‘‰ Use this if your main Application.java is in a different root package than your controllers/services.

By default, Spring only scans the package of the main class and below. If your services are in a sibling package, they won't be found. Move the main class to the root package or explicitly scan components.

@SpringBootApplication @ComponentScan(basePackages = "com.devinhyderabad") public class Application { ... }
Solution 3

Define a @Bean method in a @Configuration class

๐Ÿ‘‰ Use this if the class belongs to a third-party library (you can't edit it to add @Service).

Create a configuration class that manually instantiates the object and registers it as a Spring bean.

@Configuration public class AppConfig { @Bean public ThirdPartyService thirdPartyService() { return new ThirdPartyService(); } }

๐Ÿ“‹ Version Notes

Spring Boot 2.x

Standard behavior. Throws NoSuchBeanDefinitionException.

Spring Boot 3.x

Identical behavior, but uses Jakarta EE namespaces internally.

๐Ÿง  Why this Happens

Tap to expand the deep technical explanation

You used @Autowired to inject a class, but Spring's component scanner didn't find any class annotated with @Service, @Component, or @Repository that matches that type. Spring cannot inject an object it doesn't know exists.

The HITEC City Parking Spot Analogy:

Imagine you ordered a Biryani at a restaurant, but the kitchen doesn't have any chefs who know how to cook it. The waiter can't bring you what doesn't exist.

๐Ÿ›ก๏ธ How to Prevent This Next Time

Keep your main Application.java in the root package (e.g., com.devinhyderabad) so it automatically scans all sub-packages.

Course Search
Search across all chapters & stages
๐Ÿ“–

Search the course

Type any topic โ€” branching, stash, rebase, hooks โ€” and jump straight to that chapter.

merge branchesgit stashundo commitrebase