Spring Boot
constructor parameters
dependency injection
Java
application development

Parameter 0 of constructor in ..... Spring Boot

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The Spring Boot error that begins with Parameter 0 of constructor usually means Spring tried to create a bean, looked at the first constructor argument, and could not resolve what to inject there. The wording sounds cryptic, but the underlying issue is usually one of a few standard dependency-injection problems.

What the message actually means

Suppose Spring is creating a service like this:

java
1@Service
2public class OrderService {
3    private final PaymentClient paymentClient;
4
5    public OrderService(PaymentClient paymentClient) {
6        this.paymentClient = paymentClient;
7    }
8}

If Spring cannot find a bean of type PaymentClient, startup fails with an error that points at parameter 0, because that is the first constructor parameter.

So the message is not about numbering for its own sake. It is telling you exactly which dependency was unresolved.

The most common root causes

The most common cause is that the dependency type is not registered as a Spring bean.

For example, if PaymentClient exists as a plain Java class but has no @Component, @Service, @Repository, @Configuration, or explicit @Bean registration, Spring has nothing to inject.

Another common cause is package scanning. If your application scans com.example.app, but the dependency lives in com.example.shared outside the scan path, the bean will not be discovered.

A third common problem is ambiguity. If two beans implement the same interface and Spring does not know which one to choose, constructor injection can also fail.

A missing bean example

Here is a working version that registers the dependency properly.

java
1import org.springframework.stereotype.Component;
2import org.springframework.stereotype.Service;
3
4@Component
5public class PaymentClient {
6    public void charge() {
7        System.out.println("charging");
8    }
9}
10
11@Service
12public class OrderService {
13    private final PaymentClient paymentClient;
14
15    public OrderService(PaymentClient paymentClient) {
16        this.paymentClient = paymentClient;
17    }
18}

Now Spring can create PaymentClient first and inject it into OrderService.

Multiple beans of the same type

If you have more than one candidate bean, use @Qualifier or mark one bean as @Primary.

java
1import org.springframework.beans.factory.annotation.Qualifier;
2import org.springframework.stereotype.Component;
3import org.springframework.stereotype.Service;
4
5interface Notifier {
6    void send();
7}
8
9@Component("emailNotifier")
10class EmailNotifier implements Notifier {
11    public void send() {
12        System.out.println("email");
13    }
14}
15
16@Component("smsNotifier")
17class SmsNotifier implements Notifier {
18    public void send() {
19        System.out.println("sms");
20    }
21}
22
23@Service
24class AlertService {
25    private final Notifier notifier;
26
27    AlertService(@Qualifier("emailNotifier") Notifier notifier) {
28        this.notifier = notifier;
29    }
30}

Without the qualifier, Spring may complain that it found multiple matching beans.

Configuration-based beans

Sometimes the missing dependency comes from a library or a third-party client you create in a configuration class rather than annotating directly.

java
1import org.springframework.context.annotation.Bean;
2import org.springframework.context.annotation.Configuration;
3
4@Configuration
5public class AppConfig {
6    @Bean
7    public PaymentClient paymentClient() {
8        return new PaymentClient();
9    }
10}

This is the usual fix when the dependency class itself is not under your control.

How to debug it quickly

Read the full error message, not just the first line. Spring usually tells you the missing type and may also suggest whether no bean was found or multiple beans matched.

Then verify:

  • the dependency type is a bean
  • the bean is in a scanned package or declared with @Bean
  • there is exactly one candidate unless you use qualifiers
  • there is no circular dependency blocking creation

Those four checks resolve most constructor-parameter startup failures.

Common Pitfalls

A common mistake is creating a helper class with new in some places and expecting Spring to inject it elsewhere without registering it as a bean.

Another issue is forgetting package-scan boundaries. A correctly annotated bean is still invisible if it lives outside the scan scope.

It is also easy to treat the error as a constructor problem when the real issue is bean registration or ambiguity. The constructor is just where the failure becomes visible.

Summary

  • 'Parameter 0 of constructor means Spring could not resolve the first constructor dependency.'
  • The usual causes are missing bean registration, package scanning issues, or multiple matching beans.
  • Register dependencies with stereotypes or @Bean methods.
  • Use @Qualifier or @Primary when more than one bean matches.
  • Read the full startup error; it usually names the missing or ambiguous type directly.

Course illustration
Course illustration

All Rights Reserved.