title: Unsatisfied dependency expressed through constructor parameter 0 in Springboot
body: <p>I am getting this error very first time while executing the below code on Springboot platform. I did search for this error and it was suggested at some places to add @Component but it's already there.</p>
  <p>In this code, I am just selecting few records from a staging table and printing it.
  The table structure is defined as a separate class as mentioned below. I am getting this error at the starting only so all this logic is not being triggered as of now.</p>
  <p><strong>Error:</strong></p>
  <pre><code>org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationMainTblLoadRun': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'payConsumerMainTblLoad' defined in file [C:\Users\Documents\workspace-sts-3.9.1.RELEASE\pe_enrollment_kafkaV3\target\classes\com\example\consumer\PayConsumerMainTblLoad.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.consumer.PayConsumerMainTblLoad]: Constructor threw exception; nested exception is java.lang.NullPointerException
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:227) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:893) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
      at com.example.consumer.ApplicationMainTblLoadRun.main(ApplicationMainTblLoadRun.java:22) [classes/:na]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]
      at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.3.1.RELEASE.jar:2.3.1.RELEASE]
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'payConsumerMainTblLoad' defined in file [C:\Users\Documents\workspace-sts-3.9.1.RELEASE\target\classes\com\example\consumer\PayConsumerMainTblLoad.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.consumer.PayConsumerMainTblLoad]: Constructor threw exception; nested exception is java.lang.NullPointerException
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1320) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1304) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1224) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:884) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      ... 25 common frames omitted
  Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.consumer.PayConsumerMainTblLoad]: Constructor threw exception; nested exception is java.lang.NullPointerException
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:217) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1312) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      ... 37 common frames omitted
  Caused by: java.lang.NullPointerException: null
      at com.example.consumer.PayConsumerMainTblLoad.&lt;init&gt;(PayConsumerMainTblLoad.java:29) ~[classes/:na]
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_131]
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_131]
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_131]
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_131]
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:204) ~[spring-beans-5.2.7.RELEASE.jar:5.2.7.RELEASE]
      ... 39 common frames omitted
  </code></pre>
  <p><strong>My code hierarchy :</strong></p>
  <pre><code>ApplicationMainTblLoadRun
   -- PayConsumerMainTblLoad
      -- PayConsumerEnrollmentDetails
  </code></pre>
  <p><strong>ApplicationMainTblLoadRun :</strong></p>
  <pre><code>package com.example.consumer;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  
  @SpringBootApplication
  public class ApplicationMainTblLoadRun {
      
      @Autowired
      private static PayConsumerMainTblLoad mainTblLoad;
      
      public ApplicationMainTblLoadRun(PayConsumerMainTblLoad mainTblLoad){
          
          ApplicationMainTblLoadRun.mainTblLoad = mainTblLoad;
      }
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          
          SpringApplication.run(ApplicationMainTblLoadRun.class, args);
          
          mainTblLoad.dbLoadMaintable();
  
      }
  
      
  }
  </code></pre>
  <p><strong>PayConsumerMainTblLoad:</strong></p>
  <pre><code>package com.example.consumer;
  
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.util.List;
  
  import javax.sql.DataSource;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.jdbc.core.JdbcTemplate;
  import org.springframework.jdbc.core.RowMapper;
  import org.springframework.stereotype.Component;
  
  @Component
  public class PayConsumerMainTblLoad {
      
      private static String id        ;
      private static String id_type   ;
      private static String vp_ind        ;
      private static String ah_ind        ;
      private static String eff_dt        ;
      private static String end_dt        ;
      private static String err_val       ;
      
      @Autowired
      PayOracleDBConfig dbConfig;
      
      //Set datasource for jdbcTeample
      DataSource dataSource = dbConfig.dataSource();
      JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
      
      public void dbLoadMaintable() {
          
          //Fetch unprocessed records from staging table
          String sql = &quot;SELECT id, id_type, vp_ind, ah_ind, eff_dt, end_dt &quot;
                  + &quot;FROM fsg_prcb_file_stg WHERE process_flg = 'I'&quot;;
      
          
          RowMapper&lt;PayConsumerEnrollmentDetails&gt; rowMapper = new RowMapper&lt;PayConsumerEnrollmentDetails&gt;(){
  
              @Override
              public PayConsumerEnrollmentDetails mapRow(ResultSet result, int row ) throws SQLException {
                  // TODO Auto-generated method stub
                  
                  id          = result.getString(&quot;id&quot;);
                  id_type     = result.getString(&quot;id_type&quot;);
                  vp_ind      = result.getString(&quot;vp_ind&quot;);
                  ah_ind      = result.getString(&quot;ah_ind&quot;);
                  eff_dt      = result.getString(&quot;eff_dt&quot;);
                  end_dt      = result.getString(&quot;end_dt&quot;);
                  
                  return new PayConsumerEnrollmentDetails(id, id_type, vp_ind, ah_ind, eff_dt, end_dt);
              }
              
          };
          
          List&lt;PayConsumerEnrollmentDetails&gt; enrolDetails = jdbcTemplate.query(sql, rowMapper);
          
          for (PayConsumerEnrollmentDetails enrolDetail: enrolDetails) {
              
              System.out.println(enrolDetail);
              
          }
      
      }
      
  
  }
  </code></pre>
  <p><strong>PayConsumerEnrollmentDetails:</strong></p>
  <pre><code>package com.example.consumer;
  
  import org.springframework.stereotype.Component;
  
  public class PayConsumerEnrollmentDetails {
  
      private String id;
      private String id_type;
      private String vp_ind;
      private String ah_ind;
      private String eff_dt;
      private String end_dt;
  
      public PayConsumerEnrollmentDetails(String id, String id_type, String vp_ind,
              String ah_ind, String eff_dt, String end_dt) {
          
          super();
          this.id = id;
          this.id_type = id_type;
          this.vp_ind = vp_ind;
          this.ah_ind = ah_ind;
          this.eff_dt = eff_dt;
          this.end_dt = end_dt;
      }
  
      public String getid() {
          return id;
      }
  
      public void setid(String id) {
          this.id = id;
      }
  
      public String getid_type() {
          return id_type;
      }
  
      public void setid_type(String id_type) {
          this.id_type = id_type;
      }
  
      public String getvp_ind() {
          return vp_ind;
      }
  
      public void setvp_ind(String vp_ind) {
          this.vp_ind = vp_ind;
      }
  
      public String getah_ind() {
          return ah_ind;
      }
  
      public void setah_ind(String ah_ind) {
          this.ah_ind = ah_ind;
      }
  
      public String geteff_dt() {
          return eff_dt;
      }
  
      public void seteff_dt(String eff_dt) {
          this.eff_dt = eff_dt;
      }
  
      public String getend_dt() {
          return end_dt;
      }
  
      public void setend_dt(String end_dt) {
          this.end_dt = end_dt;
      }
  
  }
  </code></pre>