title: BeanInstantiationException due to java.lang.NullPointerException
body: <p>I am running an annotation-based configuration project such as :</p>
  
  <pre><code>@Configuration
  public class HibernateConfig {
  
      private Map&lt;String, String&gt; map;
  
      public HibernateConfig(){
          init();
      }
  
      private void init(){
          Properties props;
          InputStream input = null;
          try {
              props = new Properties();
              input = this.getClass().getClassLoader().getResourceAsStream("jdbc.properties");
              props.load(input);
              Enumeration&lt;?&gt; e = props.propertyNames();
              while (e.hasMoreElements()) {
                  String key = (String) e.nextElement();
                  String value = props.getProperty(key);
                  map.put(key, value);
              }
          } catch (IOException e1) {
              e1.printStackTrace();
          } finally{
              if(input!=null){
                  try {
                      input.close();
                  } catch (IOException e2) {
                      e2.printStackTrace();
                  }
              }
          }
      }
  
      @Bean(name="dataSource", destroyMethod = "close")
      public DataSource getDataSource(){  
          ComboPooledDataSource dataSource = new ComboPooledDataSource();
          try {
              dataSource.setDriverClass(map.get("db.driverClass"));
              dataSource.setJdbcUrl(map.get("db.jdbcUrl"));
              dataSource.setUser(map.get("db.user"));
              dataSource.setPassword(map.get("db.password"));
              dataSource.setMaxPoolSize(50);
              dataSource.setMinPoolSize(5);
              dataSource.setMaxConnectionAge(1800);
              dataSource.setMaxIdleTime(1800);
              dataSource.setAutoCommitOnClose(false);
              dataSource.setInitialPoolSize(5);
          } catch (PropertyVetoException e) {
              e.printStackTrace();
          }
          return dataSource;
      }
  
      @Bean(name="sessionFactory")
      @Scope("singleton")
      public  FactoryBean&lt;SessionFactory&gt; getSessionFactory(@Qualifier("dataSource") javax.sql.DataSource dataSource){
          LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean();
          Properties hibernateProperties = new Properties();
          hibernateProperties.setProperty("hibernate.dialect", map.get("db.dialect"));
          hibernateProperties.setProperty("hibernate.jdbc.batch_size", "0");
          hibernateProperties.setProperty("c3p0.acquire_increment", "1");
          localSessionFactoryBean.setHibernateProperties(hibernateProperties);
          try {
              localSessionFactoryBean.afterPropertiesSet();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return localSessionFactoryBean;
      }
  
      @Bean(name="transactionManager")
      public HibernateTransactionManager getTransactionManager(@Qualifier("sessionFactory") SessionFactory sessionFactory){
          HibernateTransactionManager transactionManager = new HibernateTransactionManager();
          return transactionManager;
      }
  
      public Map&lt;String, String&gt; getMap() {
          return map;
      }
  
      public void setMap(Map&lt;String, String&gt; map) {
          this.map = map;
      }
  }
  </code></pre>
  
  <p>The output of the stackrace gives me the following exception : </p>
  
  <pre><code>ERROR ContextLoader - Context initialization failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com..web.config.HibernateConfig#0' defined in class path resource [META-INF/spring/daoContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com..web.config.HibernateConfig$$EnhancerBySpringCGLIB$$49b2842b]: Constructor threw exception; nested exception is java.lang.NullPointerException
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com..web.config.HibernateConfig$$EnhancerBySpringCGLIB$$49b2842b]: Constructor threw exception; nested exception is java.lang.NullPointerException
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098)
      ... 22 more
  Caused by: java.lang.NullPointerException
      at java.util.Properties$LineReader.readLine(Properties.java:434)
      at java.util.Properties.load0(Properties.java:353)
      at java.util.Properties.load(Properties.java:341)
      at com..web.config.HibernateConfig.init(HibernateConfig.java:35)
      at com..web.config.HibernateConfig.&lt;init&gt;(HibernateConfig.java:26)
      at com..web.config.HibernateConfig$$EnhancerBySpringCGLIB$$49b2842b.&lt;init&gt;(&lt;generated&gt;)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
      ... 24 more
  Jun 16, 2017 2:55:14 PM org.apache.catalina.core.StandardContext listenerStart
  SCHWERWIEGEND: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com..web.config.HibernateConfig#0' defined in class path resource [META-INF/spring/daoContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com..web.config.HibernateConfig$$EnhancerBySpringCGLIB$$49b2842b]: Constructor threw exception; nested exception is java.lang.NullPointerException
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com..web.config.HibernateConfig$$EnhancerBySpringCGLIB$$49b2842b]: Constructor threw exception; nested exception is java.lang.NullPointerException
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098)
      ... 22 more
  Caused by: java.lang.NullPointerException
      at java.util.Properties$LineReader.readLine(Properties.java:434)
      at java.util.Properties.load0(Properties.java:353)
      at java.util.Properties.load(Properties.java:341)
      at com..web.config.HibernateConfig.init(HibernateConfig.java:35)
      at com..web.config.HibernateConfig.&lt;init&gt;(HibernateConfig.java:26)
      at com..web.config.HibernateConfig$$EnhancerBySpringCGLIB$$49b2842b.&lt;init&gt;(&lt;generated&gt;)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
      ... 24 more
  
  INFO  SessionListener - # flyway migration...
  Jun 16, 2017 2:55:14 PM org.apache.catalina.core.StandardContext listenerStart
  SCHWERWIEGEND: Exception sending context initialized event to listener instance of class com..web.listener.FlywayListener
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com..web.config.HibernateConfig#0' defined in class path resource [META-INF/spring/daoContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com..web.config.HibernateConfig$$EnhancerBySpringCGLIB$$49b2842b]: Constructor threw exception; nested exception is java.lang.NullPointerException
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com..web.config.HibernateConfig$$EnhancerBySpringCGLIB$$49b2842b]: Constructor threw exception; nested exception is java.lang.NullPointerException
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098)
      ... 22 more
  Caused by: java.lang.NullPointerException
      at java.util.Properties$LineReader.readLine(Properties.java:434)
      at java.util.Properties.load0(Properties.java:353)
      at java.util.Properties.load(Properties.java:341)
      at com..web.config.HibernateConfig.init(HibernateConfig.java:35)
      at com..web.config.HibernateConfig.&lt;init&gt;(HibernateConfig.java:26)
      at com..web.config.HibernateConfig$$EnhancerBySpringCGLIB$$49b2842b.&lt;init&gt;(&lt;generated&gt;)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
      at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
      ... 24 more
  </code></pre>
  
  <p>I have been looking for a thread talking about the same issue I could not find any so far. Any one has an idea please?</p>
  
  <p><strong>UPDATE</strong> : Stacktrace added</p>