2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

org.springframework.beans.factory.BeanCreationException :Instantiation of bean failed

public class Vahicle{    

private Test test;
    public OrderManager(Test t){    

    this.test= t;  

  }
    .....
}


<bean id="Vahicle" class="com.testing.Vahicle">    

       <property name="test" ref="test"/>

</bean>

Getting Error 


Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name "Vahicle" defined in class path resource [applicationContex.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.testing.Vahicle]: No default constructor found;


userimage

Basically when spring container trying to create the object of Vahicle class  it searching for Default constructor in Vahicle class,Which is not present

That why is giving the error.

To fix the issue there is two solution

1: use the Setter Injection to inject the dependency

2: provide the no-arg constructuctor in Vahicle class


Answer is