Wednesday, 18 July 2018

What is no Auto-wiring mode in Spring?

Click here to watch on Youtube:

Click the below Image to Enlarge:

What is no Auto-wiring mode in Spring?

<project xmlns="" xmlns:xsi=""



        <!-- Spring 5 dependencies -->


package com.ram.model;

public class Address
    private String city;
    private String state;
    private String country;

    public Address(String city, String state, String country)
    { = city;
        this.state = state; = country;

    public String toString()
        return "Address [city=" + city + ", state=" + state + ", country="
                + country + "]";


package com.ram.model;

public class Employee
    private String name;
    private Address address;

    public Employee(String name)
        System.out.println("Employee(String name) constructor "
                + "is called by the Spring container"); = name;

    public Employee(String name, Address address)
        System.out.println("Employee(String name, Address address) "
                + "constructor is called by the Spring container"); = name;
        this.address = address;

    public void displayEmployeeDetails()
                "Employee [name=" + name + ", address=" + address + "]");



<beans xmlns=""

    <bean id="address" class="com.ram.model.Address" >
        <constructor-arg value="Chennai"></constructor-arg>
        <constructor-arg value="Tamil Nadu"></constructor-arg>
        <constructor-arg value="India"></constructor-arg>

    <bean id="employee" class="com.ram.model.Employee" autowire="no">
        <constructor-arg value="Peter"></constructor-arg>


package com.ram.core;

import org.springframework.context.ApplicationContext;

import com.ram.model.Employee;

public class App
    public static void main(String[] args)
        ApplicationContext context = new ClassPathXmlApplicationContext(


        Employee employee = (Employee) context.getBean("employee");
                "Got employee object from the ApplicationContext[Spring Container]");



Jul 03, 2018 9:15:42 AM prepareRefresh
INFO: Refreshing startup date [Tue Jul 03 09:15:42 IST 2018]; root of context hierarchy
Jul 03, 2018 9:15:42 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Employee(String name) constructor is called by the Spring container
Got employee object from the ApplicationContext[Spring Container]
Employee [name=Peter, address=null]

Click the below link to download the code:

Github Link:

Bitbucket Link:

See also:

  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Spring Tutorial
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Cooking Tutorial
  • No comments:

    Post a comment