Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Overview

In this quick tutorial, we’ll explain Spring’s UnsatisfiedDependencyException, what causes it and how to avoid it.

2. Cause of UnsatisfiedDependencyException

UnsatisfiedDependencyException gets thrown when, as the name suggests, some bean or property dependency isn’t satisfied.

This may happen when a Spring application tries to wire a bean and can’t resolve one of the mandatory dependencies.

3. Example Application

Suppose we have a service class PurchaseDeptService, which depends on InventoryRepository:

@Service
public class PurchaseDeptService {
    public PurchaseDeptService(InventoryRepository repository) {
        this.repository = repository;
    }
}
public interface InventoryRepository {
}
@Repository
public class ShoeRepository implements InventoryRepository {
}
@SpringBootApplication
public class SpringDependenciesExampleApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringDependenciesExampleApplication.class, args);
    }
}

For now, we’ll assume that all these classes are located in the same package named com.baeldung.dependency.exception.app.

When we run this Spring Boot application, everything works fine.

Let’s see what kind of issues we can run into if we skip a configuration step.

4. Component Annotation Missing

Now let’s remove the @Repository annotation from our ShoeRepository class:

public class ShoeRepository implements InventoryRepository {
}

When we start our application again, we’ll see the following error message: UnsatisfiedDependencyException: Error creating bean with name ‘purchaseDeptService’: Unsatisfied dependency expressed through constructor parameter 0

Spring wasn’t instructed to wire a ShoeRepository bean and add it to the application context, so it couldn’t inject it and threw the exception.

Adding the @Repository annotation back onto the ShoeRepository solves the issue.

5. Package Not Scanned

Let’s now put our ShoeRepository (along with InventoryRepository) into a separate package named com.baeldung.dependency.exception.repository.

Once again, when we run our app, it throws the UnsatisfiedDependencyException.

To solve this, we can configure the package scan on the parent package and make sure that all relevant classes are included:

@SpringBootApplication
@ComponentScan(basePackages = {"com.baeldung.dependency.exception"})
public class SpringDependenciesExampleApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringDependenciesExampleApplication.class, args);
    }
}

6. Non-unique Dependency Resolution

Suppose we add another InventoryRepository implementation — DressRepository:

@Repository
public class DressRepository implements InventoryRepository {
}

Now when we run our app, it will once again throw the UnsatisfiedDependencyException.

However, this time the situation is different. As it happens, the dependency cannot be resolved when there’s more than one bean that satisfies it.

To solve this, we may want to add @Qualifier to distinguish between the repositories:

@Qualifier("dresses")
@Repository
public class DressRepository implements InventoryRepository {
}
@Qualifier("shoes")
@Repository
public class ShoeRepository implements InventoryRepository {
}

Also, we’ll have to add a qualifier to PurchaseDeptService constructor dependency:

public PurchaseDeptService(@Qualifier("dresses") InventoryRepository repository) {
    this.repository = repository;
}

This will make DressRepository the only viable option, and Spring will inject it into PurchaseDeptService.

7. Conclusion

In this article, we saw several most common cases of encountering UnsatisfiedDependencyException, and then we learned how to solve these problems.

We also have a more general tutorial on Spring BeanCreationException.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW