Create a Class User having following data members
Name (String)
Phone (String) T
Address (Address Class) -> Perform Dependency Injection
Team (Team Class) -> Perform Dependency Injection
Address Class have following data members
Address Line 1 (String)
Address Line 2 (String)
City (String)
State (String)
PINCODE (Integer)
Team Class have following data
Team Name (String) >> To be taken from properties file
Number of members (Integer) >> To be taken from properties file
Project (Project Class) -> Dependency Injections
Project Class have following Data
List of Sub Projects (Array List)
Implement the same using Spring 5 Annotation and XML Approaches
Create Beans for multiple employees and fetch the same in the Main Class.
Note: Create two different projects one for Annotations Based Approach and other for XML based approach.
@Component
public class User {
private String name;
private String phone;
@Autowired
private Address address;
@Autowired
private Team team;
}
@Component("address")
public class Address {
private String addressLine1;
private String addressLine2;
private String city;
private String state;
private int pincode;
}
@Component("team")
@PropertySource("classpath:team.properties")
public class Team {
@Value("${team-name}")
private String teamName;
@Value("${number-of-members}")
private int numberOfMembers;
@Autowired
private Project project;
}
import java.util.ArrayList;
@Component("project")
public class Project {
private ArrayList<Project> subProjects;
}
Comments
Leave a comment