Injecting Reference Type | Practical Code Examples | Spring Tutorial

Опубликовано: 28 Сентябрь 2024
на канале: Unity Coding
93
6

In this Video I Will Show How You Can Achieve Injecting Reference Type In Spring Java
Introduction 00:00
Example Start 00:51

Add These Dependencies in Pom.xml File

Spring-Core Dependency - Link Click on the Link Below to Add Dependency
https://mvnrepository.com/artifact/or...

Spring-Context Dependency - Link Click on the Link Below to Add Dependency
https://mvnrepository.com/artifact/or...

Add This Tag in NewFIle.Xml
Beans Tag Code
beans xmlns="http://www.springframework.org/schema..."
xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst..."
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema...
https://www.springframework.org/schem..."

Address Class Code
public class Address
{
private int street;
private String Area;

public String toString() {
return "Address [street=" + street + ", Area=" + Area + "]";
}
public Address(int street, String area) {
super();
this.street = street;
Area = area;
}
}

Employee Class Code
package Reference;

public class Employee
{
private String Name;
private Address address;
public String getName() {
return Name;
}

public Address getAddress() {
return address;
}

public void setAddress(Address address) {
this.address = address;
}

public void setName(String name) {
Name = name;
}

public String toString() {
return "Employee [Name=" + Name + ", address=" + address + "]";

}

}


Main Class Code

public class App
{
public static void main(String[]args)
{

ApplicationContext ctx = new ClassPathXmlApplicationContext("NewFile.xml");
Person person = (Person)ctx.getBean("const");
System.out.println(person);
}

}


DISCLAIMER: This channel does not promote or encourage any illegal activities, all contents provided by this channel is meant for educational purpose only,

Video Editor : Afnan Guides
Copyright Disclaimer :- Under Section 107 of the Copyright Act 1976, allowance is made for fair use for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use.

-This video is for educational purpose only.

🔹️THANKS FOR WATCHING THIS VIDEO....!!!! 👇
. I hope this video will be helpful to you.
Best of Luck....!