title: Error while creating bean through Constructor Injection,
body: <p>I am learning Spring and trying the constructor injection. But I am getting IllegalArgumentException while doing so.</p>
  
  <p>Here is my project structure - </p>
  
  <p><a href="https://i.stack.imgur.com/xP9sg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xP9sg.png" alt="enter image description here"></a></p>
  
  <p>applicationContext.xml -</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version = "1.0" encoding = "UTF-8"?&gt;
  
  &lt;beans xmlns = "http://www.springframework.org/schema/beans"
           xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation = "http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;
  
      &lt;bean id="userDataService" class="com.test.service.UserDataServiceImpl"&gt;
          &lt;constructor-arg index="0" ref="userData" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="userData" class="com.test.repository.UserDataImpl" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>My class with main method that loads the applicationContext and creates the beans. </p>
  
  <pre><code>package com.test.main;
  
  import java.util.List;
  
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  import com.test.model.User;
  import com.test.service.UserDataService;
  import com.test.service.UserDataServiceImpl;
  
  
  public class ApplicationDriver {
      public static void main(String args[])
      {
          ApplicationContext context = new 
                ClassPathXmlApplicationContext("applicationContext.xml");
          UserDataService userService = 
                context.getBean("userDataService",UserDataServiceImpl.class);
  
          List&lt;User&gt; users = userService.findAll();
          for(User user : users)
               System.out.println(user);
        }
  }
  </code></pre>
  
  <p>UserDataServiceImpl class - </p>
  
  <pre><code>package com.test.service;
  
  import java.util.List;
  
  import com.test.model.User;
  import com.test.repository.UserData;
  
  public class UserDataServiceImpl implements UserDataService {
       private UserData userData;
  
       public UserDataServiceImpl(UserData userData){
              this.userData=userData;
              System.out.println("Creating UserDataServiceImpl");
  
       }
  
       public UserDataServiceImpl(){
            System.out.println("**** Created ");
       }
  
      //  public void setUserData(UserData userData){
      //      this.userData = userData;
      //  }
      //  
     @Override
     public User findById(int id){
         return this.userData.findById(id);
     }
  
      @Override
      public List&lt;User&gt; findAll(){
          return this.userData.findAll();
      }
   }
  </code></pre>
  
  <p>UserDataImpl class - </p>
  
  <pre><code>   package com.test.repository;
  
     import java.util.ArrayList;
     import java.util.List;
     import com.test.model.User;
     import com.test.customexception.*;
  
     public class UserDataImpl implements UserData {
           List&lt;User&gt; users;
  
           public UserDataImpl(){
               System.out.println("Creating UserDataImpl");
               this.users = new ArrayList&lt;User&gt;();
               User u1 = new User(1,"A","B","C","D",12331221);
               User u2 = new User(2,"AA","BB","CC","DD",12331221);
               User u3 = new User(3,"a","b","c","d",12331221);
               User u4 = new User(4,"aa","bb","cc","dd",12331221);
               User u5 = new User(5,"Aa","Bb","Cc","Dd",12331221);
               User u6 = new User(6,"aA","bB","cC","dD",12331221);
  
               users.add(u1);
               users.add(u2);
               users.add(u3);
               users.add(u4);
               users.add(u5);
               users.add(u6);
  
        }
  
  
  
      @Override
      public User findById(int id){
           for(User user : users)
               if(user.getId() == id)
                   return user;
           return null;
      }
  
      @Override
      public List&lt;User&gt; findAll(){
          return users;
      }
  }
  </code></pre>
  
  <p>Exception - </p>
  
  <pre><code>Feb 13, 2018 6:50:03 PM 
  org.springframework.context.support.AbstractApplicationContext 
  prepareRefresh
  INFO: Refreshing 
  org.springframework.context.support.ClassPathXmlApplicationContext@4b85612c: 
  startup date [Tue Feb 13 18:50:03 IST 2018]; root of context hierarchy
  Feb 13, 2018 6:50:03 PM 
  org.springframework.beans.factory.xml.XmlBeanDefinitionReader 
  loadBeanDefinitions
  INFO: Loading XML bean definitions from class path resource 
  [applicationContext.xml]
  Feb 13, 2018 6:50:03 PM 
  org.springframework.beans.factory.support.DefaultListableBeanFactory 
  preInstantiateSingletons
  INFO: Pre-instantiating singletons in 
  org.springframework.beans.factory.support. 
  DefaultListableBeanFactory@3fb6a447: defining beans 
  [userDataService,userData]; root of factory hierarchy
  Creating UserDataImpl
  Exception in thread "main" java.lang.IllegalArgumentException
  at org.springframework.asm.ClassReader.&lt;init&gt;(Unknown Source)
  at org.springframework.asm.ClassReader.&lt;init&gt;(Unknown Source)
  at org.springframework.asm.ClassReader.&lt;init&gt;(Unknown Source)
  at org.springframework.core. 
  LocalVariableTableParameterNameDiscoverer. 
  inspectClass(LocalVariableTableParameterNameDiscoverer.java:110)
  at org.springframework.core.LocalVariableTableParameterNameDiscoverer. 
  getParameterNames(LocalVariableTableParameterNameDiscoverer.java:85)
  at org.springframework.beans.factory.support.ConstructorResolver. 
  autowireConstructor(ConstructorResolver.java:193)
  at 
  org.springframework.beans.factory.support. 
  AbstractAutowireCapableBeanFactory. 
  autowireConstructor(AbstractAutowireCapableBeanFactory.java:1051)
  at 
  org.springframework.beans.factory.support. 
  AbstractAutowireCapableBeanFactory. 
  createBeanInstance(AbstractAutowireCapableBeanFactory.java:955)
  at 
  org.springframework.beans.factory.support. 
  AbstractAutowireCapableBeanFactory. 
  doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
  at 
  org.springframework.beans.factory.support. 
  AbstractAutowireCapableBeanFactory. 
  createBean(AbstractAutowireCapableBeanFactory.java:461)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1. 
  getObject(AbstractBeanFactory.java:295)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry. 
  getSingleton(DefaultSingletonBeanRegistry.java:223)
  at org.springframework.beans.factory.support.AbstractBeanFactory. 
  doGetBean(AbstractBeanFactory.java:292)
  at org.springframework.beans.factory.support.AbstractBeanFactory. 
  getBean(AbstractBeanFactory.java:194)
  at 
  org.springframework.beans.factory.support.DefaultListableBeanFactory. 
  preInstantiateSingletons(DefaultListableBeanFactory.java:626)
  at org.springframework.context.support.AbstractApplicationContext. 
  finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
  at org.springframework.context.support.AbstractApplicationContext. 
  refresh(AbstractApplicationContext.java:479)
  at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;
  (ClassPathXmlApplicationContext.java:139)
  at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;
  (ClassPathXmlApplicationContext.java:83)
  at com.test.main.ApplicationDriver.main(ApplicationDriver.java:16)
  </code></pre>
  
  <p>Line 16 in ApplicationDriver class is - </p>
  
  <pre><code>ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
  </code></pre>
  
  <p>Interfaces and User Model class - 
  UserData Interface - </p>
  
  <pre><code>package com.test.repository;
  
  import java.util.List;
  
  import com.test.model.User;
  
  public interface UserData {
  
       User findById(int id);
  
       List&lt;User&gt; findAll();
  
  }
  </code></pre>
  
  <p>UserDataService Interface - </p>
  
  <pre><code>package com.test.service;
  
  import java.util.List;
  
  import com.test.model.User;
  
  public interface UserDataService {
  
      User findById(int id);
  
      List&lt;User&gt; findAll();
  
  }
  </code></pre>
  
  <p>Data Model class -</p>
  
  <pre><code>package com.test.model;
  
  public class User {
  private String address;
  private String email;
  private String firstName;
  private int id;
  private String lastName;
  private long phone;
  
  public User(int id, String firstName, String lastName, String address, 
              String email, long phone) {
      super();
      this.id = id;
      this.firstName = firstName;
      this.lastName = lastName;
      this.address = address;
      this.email = email;
      this.phone = phone;
  }
  
  public String getAddress() {
      return address;
  }
  
  public String getEmail() {
      return email;
  }
  
  public String getFirstName() {
      return firstName;
  }
  
  public int getId() {
      return id;
  }
  
  public String getLastName() {
      return lastName;
  }
  
  public long getPhone() {
      return phone;
  }
  
  public void setAddress(String address) {
      this.address = address;
  }
  
  public void setEmail(String email) {
      this.email = email;
  }
  
  public void setFirstName(String firstName) {
      this.firstName = firstName;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  public void setLastName(String lastName) {
      this.lastName = lastName;
  }
  
  public void setPhone(long phone) {
      this.phone = phone;
  }
  
  @Override
  public String toString(){
      return new String("User : "+this.getId()+" "+this.getFirstName()+" 
      "+this.getLastName()+" "+this.getEmail());
   }
  
  }
  </code></pre>