Skip to main content
added 48 characters in body
Source Link
rakesh mehra
  • 652
  • 1
  • 11
  • 26

I have a Class that accepts the following constructor

 public Student(int id, String name, Map<String, List<String>> mapInject) { super(); this.id = id; this.name = name; this.mapInject = mapInject; } 

And from spring Java Config, I am injecting the constructor args like below..

@Configuration public class JavaConfig { @Bean public Employee getEmployeeBean() { Map<String,List<String>> mapInject = new HashMap<String,List<String>>(); //Add map element return new Employee(3123,"John",mapInject); } } 

Am i doing constructor injection here? Is this the right way to do so?

I have a Class that accepts the following constructor

 public Student(int id, String name, Map<String, List<String>> mapInject) { super(); this.id = id; this.name = name; this.mapInject = mapInject; } 

And from spring Java Config, I am injecting the constructor args like below..

@Configuration public class JavaConfig { @Bean public Employee getEmployeeBean() { Map<String,List<String>> mapInject = new HashMap<String,List<String>>(); //Add map element return new Employee(3123,"John",mapInject); } } 

Is this the right way?

I have a Class that accepts the following constructor

 public Student(int id, String name, Map<String, List<String>> mapInject) { super(); this.id = id; this.name = name; this.mapInject = mapInject; } 

And from spring Java Config, I am injecting the constructor args like below..

@Configuration public class JavaConfig { @Bean public Employee getEmployeeBean() { Map<String,List<String>> mapInject = new HashMap<String,List<String>>(); //Add map element return new Employee(3123,"John",mapInject); } } 

Am i doing constructor injection here? Is this the right way to do so?

Source Link
rakesh mehra
  • 652
  • 1
  • 11
  • 26

Spring constructor injection using java config

I have a Class that accepts the following constructor

 public Student(int id, String name, Map<String, List<String>> mapInject) { super(); this.id = id; this.name = name; this.mapInject = mapInject; } 

And from spring Java Config, I am injecting the constructor args like below..

@Configuration public class JavaConfig { @Bean public Employee getEmployeeBean() { Map<String,List<String>> mapInject = new HashMap<String,List<String>>(); //Add map element return new Employee(3123,"John",mapInject); } } 

Is this the right way?