April 2018
Intermediate to advanced
246 pages
6h 11m
English
We have seen how the factory method is created and configured to generate beans with XML-based configuration. Spring supports annotation for the factory method also. Let's take the same example, and understand how to write annotation for the factory method:
public class Employee { private String type; public Employee(String type) { this.type = type; } public void showType() { System.out.println("Type is :"+type); }}public class Developer extends Employee { public Developer(String type) { super(type); }}public class Manager extends Employee { public Manager(String type) { super(type); }}@Componentpublic class EmployeeService { //Instance Factory method with annotation @Bean("developerBean") public Employee ...