Добавить
Уведомления

AutoWiring (byType) In Spring FrameWork | Practical Code Examples | Spring Tutorial

In this Video I Will Show How You Can Achieve Constructor Injection with Reference Type In Spring Java Introduction 00:00 Example Start 01:00 Add These Dependencies in Pom.xml File Spring-Core Dependency - Link Click on the Link Below to Add Dependency https://mvnrepository.com/artifact/org.springframework/spring-core/5.2.22.RELEASE Spring-Context Dependency - Link Click on the Link Below to Add Dependency https://mvnrepository.com/artifact/org.springframework/spring-context/5.2.22.RELEASE 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/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" bean class="auto.Address" name="address" p:street="22" p:Area="Islamabad" p:houseno="379" /bean bean class="auto.AutoWritingTest" name="byname" autowire="byType" / /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....!

Иконка канала Java Бест Практики
2 подписчика
12+
14 просмотров
2 года назад
5 декабря 2023 г.
12+
14 просмотров
2 года назад
5 декабря 2023 г.

In this Video I Will Show How You Can Achieve Constructor Injection with Reference Type In Spring Java Introduction 00:00 Example Start 01:00 Add These Dependencies in Pom.xml File Spring-Core Dependency - Link Click on the Link Below to Add Dependency https://mvnrepository.com/artifact/org.springframework/spring-core/5.2.22.RELEASE Spring-Context Dependency - Link Click on the Link Below to Add Dependency https://mvnrepository.com/artifact/org.springframework/spring-context/5.2.22.RELEASE 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/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" bean class="auto.Address" name="address" p:street="22" p:Area="Islamabad" p:houseno="379" /bean bean class="auto.AutoWritingTest" name="byname" autowire="byType" / /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....!

, чтобы оставлять комментарии