Answer to Question #282701 in Java | JSP | JSF for sahil

Question #282701
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.
1
Expert's answer
2021-12-26T09:41:35-0500
@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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog