AutoWiring through @AutoWired Annotation In Spring | Practical Code Examples | Spring Tutorial

Published: 25 March 2023
on channel: Unity Coding
44
3

In this Video I Will Show How You Can Achieve Autowiring by Constructor

Introduction 00:00
Example Start 01:15

Follow all the steps that are in video and copy paste all the code given below !!
| Best of Luck |

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...

Spring-Annotation 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 {
@Autow
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"
/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....!


Watch video AutoWiring through @AutoWired Annotation In Spring | Practical Code Examples | Spring Tutorial online without registration, duration hours minute second in high quality. This video was added by user Unity Coding 25 March 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 44 once and liked it 3 people.