Q1/- Explain about the life-cycle of a Spring Bean.
Q2/- How many scopes are there for a Spring Bean, which is the default scope for a Spring
Bean? Explain with an example.
Q3/- What is the difference between setter injection and constructor injection?
Q4/- What is auto wiring in Spring, how many types of Auto wiring are there in spring,
explain with an example.
Q5/- Consider following class :
class Employee{
empId;
empName;
address;
salary;
//use constructor injection to inject the above fields.
//override the toString method with all the above fields
class Department{
deptId;
deptName;
location;
//use constructor injection to inject the above fields.
//override the toString method with all the above fields
class Demo {
private Map<Department, Employee> theMap;
//use setter injection to inject theMap;
public void myInit(){
System.out.println(“inside myInit method”);
}
public void cleanUp(){
System.out.println(“inside cleanUp method”);
}
Public void showDetails(){
System.out.println(“inside showDetails of Demo class”);
//print all the details of all the employees department-wise.
}
Note:
● Configure 3 department objects (Sales, Marketing, Accounts), and in each
department associate one Employee object.
● Make myInit and init-method and cleanUp method as destroy method, both
should be called.
● Initialize the Demo object lazily.
● From the main method of the Demo class call the showDetails() method by pulling
the object from the Spring Container.