There are Two ways of Injecting Objects in Spring.

  • Using Getter and Setters
    Using Constructors
  • When you are trying to inject Objects using the getters and setters, you need to define Bean as

    The above Bean Definition would inject an Object Of class “GeneralBean” and set the value “message” to “Hello”

    If you want to inject Object using Constructors then you have to define the bean as shown below,

    Also, you need to define a Constructor in the POJO class.