0% found this document useful (0 votes)
2 views2 pages

Spring Core: Managing Customer & Product Beans

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Spring Core: Managing Customer & Product Beans

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Problem Statement

Time Required : 15 minutes

Objective:
Goal: Core Spring - Application context and how to create Beans
Autowiring
Define the Scope of a bean

Objective:

Extend the Spring Core application to manage both customer and product details. The
application should now include a Product class and perform autowiring of the Product
class in the Customer class.

Requirements:

1.​ Define the Customer class:


○​ The class should have private fields for cid, cname, address, and
mobileNumber.
○​ It should also have a Product field to store product details.
○​ Provide public getters and setters for each field.
○​ Override the toString method to display customer details along with the
product.
2.​ Define the Product class:
○​ The class should have private fields for pid, pname, and price.
○​ Provide public getters and setters for each field.
○​ Override the toString method to display product details.
3.​ Spring Configuration:
○​ Use Spring's Java-based configuration to define and configure Customer and
Product objects.
○​ Perform autowiring to inject the Product into the Customer class.
4.​ Main Application:
○​ Create a main application class to load the Spring context and retrieve the
Customer objects.
○​ Display the details of each customer along with their respective products using
the toString method.

Steps:
1.​ Create the Customer class.
2.​ Create the Product class.
3.​ Create a Spring configuration class to define and configure the Customer and
Product beans.
4.​ The product class needs to be with scope Singleton Class.
5.​ Create a main application class to load the Spring context and display customer
and product details.

public class Product {


private int pid;
private String pname;
private double price;

// Getters and Setters


// toString
}

You might also like