In this Video I Will Show How You Can Achieve Constructor Injection with Reference Type In Spring Java
Introduction 00:00
Example Start 01:10
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...
Address Class Code
public class Address {
private int street;
private String Area;
private int houseno;
public int getHouseno() {
return houseno;
}
public void setHouseno(int houseno) {
this.houseno = houseno;
}
public String toString() {
return "Address [street=" + street + ", Area=" + Area + ", houseno=" + houseno + "]";
}
public int getStreet() {
return street;
}
public void setStreet(int street) {
this.street = street;
}
public String getArea() {
return Area;
}
public void setArea(String area) {
Area = area;
}
}
AutoWiringTest Class Code
public class AutoWritingTest {
private Address address;
public AutoWritingTest() {
super();
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public AutoWritingTest(Address address) {
super();
this.address = address;
}
public String toString() {
return "AutoWritingTest [address=" + address + "]";
}
}
NewFile.Xml Code
?xml version="1.0" encoding="UTF-8"?
beans xmlns="http://www.springframework.org/schema..."
xmlns:context="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...
http://www.springframework.org/schema...
http://www.springframework.org/schema...
http://www.springframework.org/schema..."
bean class="auto.Address" name="address" p:street="22"
p:Area="Islamabad" p:houseno="379"
/bean
bean class="auto.AutoWritingTest" name="byname" autowire="byName" /
/beans
Main Class Code
public class App {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("NewFile.xml");
AutoWritingTest person = (AutoWritingTest) ctx.getBean("byname");
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....!
Auf dieser Seite können Sie das Online-Video AutoWiring (byName) In Spring FrameWork | Practical Code Examples | Spring Tutorial mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Unity Coding 25 März 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 57 Mal angesehen und es wurde von 3 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!