Lara

Spring

Saturday(7-1-2017)

app1

package com.lara;

 

public class Person

{

            private String firstName;

            private String lastName;

            private Integer age;

            public String getFirstName() {

                        return firstName;

            }

            public void setFirstName(String firstName) {

                        this.firstName = firstName;

            }

            public String getLastName() {

                        return lastName;

            }

            public void setLastName(String lastName) {

                        this.lastName = lastName;

            }

            public Integer getAge() {

                        return age;

            }

            public void setAge(Integer age) {

                        this.age = age;

            }

           

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager1

{

            public static void main(String[] args)

            {

                        ClassPathResource cpr = new ClassPathResource("beans.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(cpr);

                       

                        Person obj = (Person) beanFactory.getBean("p1");

                       

                        System.out.println(obj.getFirstName());

                        System.out.println(obj.getLastName());

                        System.out.println(obj.getAge());

            }

}

beans.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans.xsd">

 

       <bean id="p1" class="com.lara.Person">

                                    <property name="firstName" value="abc"/>

                                    <property name="lastName" value="xyz"/>

                                    <property name="age" value="25"/>                        

       </bean>

 

</beans>       

app2

package com.lara;

 

public class Employee

{

            private String firstName;

            private Integer age;

            private double salary;

            public String getFirstName() {

                        return firstName;

            }

            public void setFirstName(String firstName) {

                        this.firstName = firstName;

            }

            public Integer getAge() {

                        return age;

            }

            public void setAge(Integer age) {

                        this.age = age;

            }

            public double getSalary() {

                        return salary;

            }

            public void setSalary(double salary) {

                        this.salary = salary;

            }

           

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager1

{

            public static void main(String[] args) {

                        ClassPathResource cpr = new ClassPathResource("config.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(cpr);

                       

                        Employee emp = (Employee) beanFactory.getBean("e1");

                       

                        System.out.println(emp.getFirstName());

                        System.out.println(emp.getAge());

                        System.out.println(emp.getSalary());

                                               

            }

}

config.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans.xsd">

       

              <!-- bean tag is bean tag -->       

            <bean id="e1" class ="com.lara.Employee">

                        <property name="firstName" value="abc"/>

                        <property name="age" value="22"/>

                        <property name="salary" value="55000.898"/>   

    </bean> 

</beans>       

Sunday(08-01-2017)                                app3

package com.lara;

 

public class Person

{

            private String firstName;

            private String lastName;

            private String email;

            public String getFirstName()

            {

                        return firstName;

            }

            public void setFirstName(String firstName)

            {

                        this.firstName = firstName;

            }

            public String getLastName()

            {

                        return lastName;

            }

            public void setLastName(String lastName)

            {

                        this.lastName = lastName;

            }

            public String getEmail()

            {

                        return email;

            }

            public void setEmail(String email)

            {

                        this.email = email;

            }

           

           

           

           

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager1

{

            public static void main(String[] args)

            {

                        ClassPathResource resource = new ClassPathResource("config.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(resource);

                       

                        Person obj1 = (Person) beanFactory.getBean("p1");

 

                        System.out.println(obj1.getFirstName());

                        System.out.println(obj1.getLastName());

                        System.out.println(obj1.getEmail());

                       

            }

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager2

{

            public static void main(String[] args)

            {

                        ClassPathResource resource = new ClassPathResource("config.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(resource);

                       

                        Person obj1 = (Person) beanFactory.getBean("p1");

                        Person obj2 = (Person) beanFactory.getBean("p1");

                       

                        System.out.println(obj1 == obj2);

                       

            }

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager3

{

            public static void main(String[] args)

            {

                        ClassPathResource cpr = new ClassPathResource("config.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(cpr);

                       

                        Person obj1 = (Person) beanFactory.getBean("p1");

                        Person obj2 = (Person) beanFactory.getBean("p1");

                       

                        Person obj3 = (Person) beanFactory.getBean("p2");

                        Person obj4 = (Person) beanFactory.getBean("p2");

                       

                        System.out.println(obj1.getFirstName());

                        System.out.println(obj1.getLastName());

                        System.out.println(obj1.getEmail());

                       

                        System.out.println(obj3.getFirstName());

                        System.out.println(obj3.getLastName());

                        System.out.println(obj3.getEmail());

                       

                        System.out.println(obj1 == obj2);

                        System.out.println(obj3 == obj4);

                        System.out.println(obj1 == obj4);

                       

 

           

            }

}

package com.lara;

 

public class Employee

{

            private String firstName;

            private String lastName;

            private Integer age;

           

            public Employee()

            {

                        System.out.println("Employee()");

            }

           

            public void setFirstName(String firstName)

            {

                        System.out.println("setFirstName");

                        this.firstName = firstName;

            }          

            public String getFirstName()

            {

                        System.out.println("getFirstName");

                        return firstName;

            }

           

           

            public void setLastName(String lastName)

            {

                        System.out.println("setLastName");

                        this.lastName = lastName;

            }

           

            public String getLastName()

            {

                        System.out.println("getLastName");

                        return lastName;

            }

           

            public void setAge(Integer age)

            {

                        System.out.println("setAge");

                        this.age = age;

            }

            public Integer getAge()

            {

                        System.out.println("getAge");

                        return age;

            }

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager4

{

            public static void main(String[] args)

            {

                        BeanFactory beanFactory =

                                                new XmlBeanFactory(new ClassPathResource("config.xml"));

                        System.out.println("BeanFactory is ready");

                        Employee emp = (Employee) beanFactory.getBean("e1");

                        System.out.println("Employee obj is ready");

                        String firstName = emp.getFirstName();

                        String lastName = emp.getLastName();

                        Integer age = emp.getAge();

                        System.out.println("First Name:" + firstName);

                        System.out.println("Last Name:" + lastName);

                        System.out.println("Age:" + emp.getAge());

            }

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager5

{

            public static void main(String[] args)

            {

                        BeanFactory beanFactory =

                                                new XmlBeanFactory(new ClassPathResource("config.xml"));

                        System.out.println("BeanFactory is ready");

                        Employee emp = (Employee) beanFactory.getBean("e2");

                        System.out.println("Employee obj is ready");

                        Employee emp1 = (Employee) beanFactory.getBean("e2");

                        System.out.println("one more Employee obj is ready");

                        String firstName = emp.getFirstName();

                        String lastName = emp.getLastName();

                        Integer age = emp.getAge();

                        System.out.println("First Name:" + firstName);

                        System.out.println("Last Name:" + lastName);

                        System.out.println("Age:" + emp.getAge());

            }

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager6

{

            public static void main(String[] args)

            {

                        ClassPathResource cpr = new ClassPathResource("config.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(cpr);

                       

                        Employee emp = (Employee) beanFactory.getBean("e3");

                       

                        System.out.println(emp.getFirstName());

                        System.out.println(emp.getLastName());

                        System.out.println(emp.getAge());

            }

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager7

{

            public static void main(String[] args)

            {

                        ClassPathResource cpr = new ClassPathResource("config.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(cpr);

                       

                        Employee emp = (Employee) beanFactory.getBean("e4");

                       

                        System.out.println(emp.getFirstName());

                        System.out.println(emp.getLastName());

                        System.out.println(emp.getAge());

            }

}

package com.lara;

 

public class Student

{

            private String firstName;

            private String lastName;

            private Integer age;

           

            public Student()

            {

                        System.out.println("Student()");

            }

           

            public Student(String firstName, String lastName, Integer age)

            {

                        this.firstName = firstName;

                        this.lastName = lastName;

                        this.age = age;

                        System.out.println("Student(String, String, Integer)");

            }

 

            public String getFirstName()

            {

                        return firstName;

            }

 

            public String getLastName()

            {

                        return lastName;

            }

 

            public Integer getAge()

            {

                        return age;

            }

           

           

           

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager8

{

            public static void main(String[] args)

            {

                        ClassPathResource cpr = new ClassPathResource("config.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(cpr);

                       

                        Student st1 = (Student) beanFactory.getBean("s1");

                       

                        System.out.println(st1.getFirstName());

                        System.out.println(st1.getLastName());

                        System.out.println(st1.getAge());

            }

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager9

{

            public static void main(String[] args)

            {

                        ClassPathResource cpr = new ClassPathResource("config.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(cpr);

                       

                        Student st2 = (Student) beanFactory.getBean("s2");

                       

                        System.out.println(st2.getFirstName());

                        System.out.println(st2.getLastName());

                        System.out.println(st2.getAge());

            }

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager10

{

            public static void main(String[] args)

            {

                        ClassPathResource cpr = new ClassPathResource("config.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(cpr);

                        Student st2 = (Student) beanFactory.getBean("s3");

                       

                        System.out.println(st2.getFirstName());

                        System.out.println(st2.getLastName());

                        System.out.println(st2.getAge());

            }

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager11

{

            public static void main(String[] args)

            {

                        ClassPathResource cpr = new ClassPathResource("config.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(cpr);

                        Student st2 = (Student) beanFactory.getBean("s4");

                       

                        System.out.println(st2.getFirstName());

                        System.out.println(st2.getLastName());

                        System.out.println(st2.getAge());

            }

}

package com.lara;

 

public class Customer

{

            private String firstName;

            private Integer age;

           

            public Customer(String firstName, Integer age)

            {

                        System.out.println("Customer(String, Integer");

                        this.firstName = firstName;

                        this.age = age;

            }

 

            public Customer(Integer age, String firstName)

            {

                        System.out.println("Customer(Integer, String");

                        this.firstName = firstName;

                        this.age = age;

            }

 

            public String getFirstName()

            {

                        return firstName;

            }

 

            public Integer getAge()

            {

                        return age;

            }

 

           

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager12

{

            public static void main(String[] args)

            {

                        ClassPathResource cpr = new ClassPathResource("config.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(cpr);

                        Customer obj1 = (Customer) beanFactory.getBean("c1");

                       

                        System.out.println(obj1.getFirstName());

                        System.out.println(obj1.getAge());

            }

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager13

{

            public static void main(String[] args)

            {

                        ClassPathResource cpr = new ClassPathResource("config.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(cpr);

                        Customer obj1 = (Customer) beanFactory.getBean("c2");

                       

                        System.out.println(obj1.getFirstName());

                        System.out.println(obj1.getAge());

            }

}

Config.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans.xsd">

 

        <bean id="p1" class="com.lara.Person" scope="singleton">

            <property name="firstName" value="Ramu"/>

            <property name="lastName" value="Manu"/>

            <property name="email" value="r@k.com"/>

        </bean>

 

        <bean id="p2" class="com.lara.Person" scope="prototype">

            <property name="firstName" value="Manu"/>

            <property name="lastName" value="Kiran"/>

            <property name="email" value="r@m.com"/>

        </bean>

 

                        <bean id="e1" class="com.lara.Employee">

                                    <property name="firstName" value="naveen"/>

                                    <property name="lastName" value="test"/>

                                    <property name="age" value="34"/>

                        </bean>

                       

                        <bean id="e2" class="com.lara.Employee" scope="prototype">

                                    <property name="lastName" value="test"/>

                                    <property name="firstName" value="naveen"/>

                                    <property name="age" value="34"/>

                        </bean>

                       

                        <bean id="e3" class="com.lara.Employee">

                                    <property name="lastName" value="test"/>

                                    <property name="age" value="34"/>

                        </bean>

                       

                        <bean id="e4" class="com.lara.Employee"/>

                       

                        <bean id="s1" class="com.lara.Student">

                                    <constructor-arg value="abc"/>

                                    <constructor-arg value="xyz"/>

                                    <constructor-arg value="22"/>

                        </bean>

                       

                        <bean id="s2" class="com.lara.Student">

                                    <constructor-arg value="abc" index="1"/>

                                    <constructor-arg value="xyz" index="0"/>

                                    <constructor-arg value="22" index="2"/>

                        </bean>                   

                       

                        <bean id="s3" class="com.lara.Student">

                                    <constructor-arg value="22" name="age"/>

                                    <constructor-arg value="abc" name="lastName"/>

                                    <constructor-arg value="xyz" name="firstName"/>

                        </bean>                   

                                               

                        <bean id="s4" class="com.lara.Student">

                                    <constructor-arg value="abc" name="lastName" />

                                    <constructor-arg value="xyz" name="firstName"/>

                        </bean>                   

 

                        <bean id="c1" class="com.lara.Customer">

                                    <constructor-arg value="abc" index="0" type="java.lang.String"/>

                                    <constructor-arg value="22" index="1" type="java.lang.Integer"/>                           

                        </bean>

 

                        <bean id="c2" class="com.lara.Customer">

                                    <constructor-arg value="abc" index="1" type="java.lang.String"/>

                                    <constructor-arg value="22" index="0" type="java.lang.Integer"/>                           

                        </bean>

 

</beans>       

Saturday(14-01-2017)

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Util

{

            private static BeanFactory beanFactory;

           

            static

            {

                        ClassPathResource cpr = new ClassPathResource("beans.xml");

                        beanFactory = new XmlBeanFactory(cpr);

            }

           

            public static Object getBean(String obj)

            {

                        return beanFactory.getBean(obj);

            }

}

package com.lara;

 

public class Address

{

            private String houseNo;

            private String streetName;

            public String getHouseNo()

            {

                        return houseNo;

            }

            public void setHouseNo(String houseNo)

            {

                        this.houseNo = houseNo;

            }

            public String getStreetName()

            {

                        return streetName;

            }

            public void setStreetName(String streetName)

            {

                        this.streetName = streetName;

            }

           

           

           

}

package com.lara;

 

public class Manager1

{

            public static void main(String[] args)

            {

                        Address add = (Address) Util.getBean("a1");

                        System.out.println(add.getHouseNo());

                        System.out.println(add.getStreetName());

            }

}

package com.lara;

 

public class Person

{

            private String firstName;

            private Address permanentAddress;

            public String getFirstName()

            {

                        return firstName;

            }

            public void setFirstName(String firstName)

            {

                        this.firstName = firstName;

            }

            public Address getPermanentAddress()

            {

                        return permanentAddress;

            }

            public void setPermanentAddress(Address permanentAddress)

            {

                        this.permanentAddress = permanentAddress;

            }

 

           

}

 

package com.lara;

 

public class Manager2

{

            public static void main(String[] args)

            {

                        Person p1 = (Person) Util.getBean("p1");

                        System.out.println(p1.getFirstName());

                        Address add = p1.getPermanentAddress();

                        System.out.println(add.getHouseNo());

                        System.out.println(add.getStreetName());

            }

}

package com.lara;

 

import java.util.List;

import java.util.Map;

import java.util.Properties;

import java.util.Set;

 

public class Student

{

            private String firstName;

            private int age;

            private Double weight;

            private int[] marks;

            private String[] mails;

            private List subjects;

            private Set mobileNos;

            private Map educations;

            private Properties projects;

            private Address permanentAddress;

            public String getFirstName()

            {

                        return firstName;

            }

            public void setFirstName(String firstName)

            {

                        this.firstName = firstName;

            }

            public int getAge()

            {

                        return age;

            }

            public void setAge(int age)

            {

                        this.age = age;

            }

            public Double getWeight()

            {

                        return weight;

            }

            public void setWeight(Double weight)

            {

                        this.weight = weight;

            }

            public int[] getMarks()

            {

                        return marks;

            }

            public void setMarks(int[] marks)

            {

                        this.marks = marks;

            }

            public String[] getMails()

            {

                        return mails;

            }

            public void setMails(String[] mails)

            {

                        this.mails = mails;

            }

            public List getSubjects()

            {

                        return subjects;

            }

            public void setSubjects(List subjects)

            {

                        this.subjects = subjects;

            }

            public Set getMobileNos()

            {

                        return mobileNos;

            }

            public void setMobileNos(Set mobileNos)

            {

                        this.mobileNos = mobileNos;

            }

            public Map getEducations()

            {

                        return educations;

            }

            public void setEducations(Map educations)

            {

                        this.educations = educations;

            }

            public Properties getProjects()

            {

                        return projects;

            }

            public void setProjects(Properties projects)

            {

                        this.projects = projects;

            }

            public Address getPermanentAddress()

            {

                        return permanentAddress;

            }

            public void setPermanentAddress(Address permanentAddress)

            {

                        this.permanentAddress = permanentAddress;

            }

           

           

           

}

package com.lara;

 

import java.util.Arrays;

 

public class Manager3

{

            public static void main(String[] args)

            {

                        Student st1 = (Student) Util.getBean("s1");              

                        System.out.println(st1.getFirstName());

                        System.out.println(st1.getAge());

                        System.out.println(st1.getWeight());

                        System.out.println(Arrays.toString(st1.getMarks()));

                        System.out.println(Arrays.toString(st1.getMails()));

                        System.out.println(st1.getSubjects());

                        System.out.println(st1.getMobileNos());

                        System.out.println(st1.getEducations());

                        System.out.println(st1.getProjects());

                        System.out.println(st1.getPermanentAddress().getHouseNo());

                        System.out.println(st1.getPermanentAddress().getStreetName());

                        System.out.println("done");

            }

}

package com.lara;

 

import java.util.List;

import java.util.Map;

import java.util.Properties;

import java.util.Set;

 

public class Employee

{

            private String firstName;

            private int age;

            private Double weight;

            private int[] marks;

            private String[] mails;

            private List subjects;

            private Set mobileNos;

            private Map educations;

            private Properties projects;

            private Address permanentAddress;

           

            public Employee(String firstName,

                                                            int age,

                                                            Double weight,

                                                            int[] marks,

                                                            String[] mails,

                                                            List subjects,

                                                            Set mobileNos,

                                                            Map educations,

                                                            Properties projects,

                                                            Address permanentAddress)

            {

                        this.firstName = firstName;

                        this.age = age;

                        this.weight = weight;

                        this.marks = marks;

                        this.mails = mails;

                        this.subjects = subjects;

                        this.mobileNos = mobileNos;

                        this.educations = educations;

                        this.projects = projects;

                        this.permanentAddress = permanentAddress;

            }

 

            public String getFirstName()

            {

                        return firstName;

            }

 

            public int getAge()

            {

                        return age;

            }

 

            public int[] getMarks()

            {

                        return marks;

            }

 

            public String[] getMails()

            {

                        return mails;

            }

 

            public Set getMobileNos()

            {

                        return mobileNos;

            }

 

            public Map getEducations()

            {

                        return educations;

            }

 

            public Properties getProjects()

            {

                        return projects;

            }

 

            public Address getPermanentAddress()

            {

                        return permanentAddress;

            }

           

            public List getSubjects()

            {

                        return subjects;

            }

           

            public Double getWeight()

            {

                        return weight;

            }

}

package com.lara;

 

import java.util.Arrays;

 

public class Manager4

{

            public static void main(String[] args)

            {

                        Employee emp = (Employee) Util.getBean("e1");               

                        System.out.println(emp.getFirstName());

                        System.out.println(emp.getAge());

                        System.out.println(emp.getWeight());

                        System.out.println(Arrays.toString(emp.getMarks()));

                        System.out.println(Arrays.toString(emp.getMails()));

                        System.out.println(emp.getSubjects());

                        System.out.println(emp.getMobileNos());

                        System.out.println(emp.getEducations());

                        System.out.println(emp.getProjects());

                        System.out.println(emp.getPermanentAddress().getHouseNo());

                        System.out.println(emp.getPermanentAddress().getStreetName());

                        System.out.println("done");

            }

}

beans.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans.xsd">

            <bean id="a1" class="com.lara.Address">

                        <property name="houseNo" value="123/B"/>

                        <property name="streetName" value="BTM"/>

            </bean>       

            <bean id="permanentAddress" class="com.lara.Address">

                        <property name="houseNo" value="123/C"/>

                        <property name="streetName" value="JP Nagar"/>

            </bean>       

            <bean id="p1" class="com.lara.Person">

                         <property name="firstName" value="Ramu"/>

                         <property name="permanentAddress" ref="a1"/>

            </bean> 

           

            <bean id="s1" class="com.lara.Student" autowire="byType">

                        <property name="firstName" value="Vijay"/>

                        <property name="age" value="22"/>

                        <property name="weight" value="45.9"/>

                        <property name="marks">

                                    <list>

                                                <value>48</value>

                                                <value>78</value>

                                                <value>85</value>

                                    </list>

                        </property>                       

                        <property name="mails">

                                    <list>

                                                <value>a@a.com</value>

                                                <value>b@b.com</value>

                                                <value>c@c.om</value>

                                    </list>

                        </property>

                        <property name="subjects">

                                    <list>

                                                <value>maths</value>

                                                <value>cse</value>

                                                <value>english</value>

                                    </list>

                        </property>

                        <property name="mobileNos">

                                    <set>

                                                <value>9845098450</value>

                                                <value>9845098451</value>

                                                <value>9845098452</value>

                                    </set>

                        </property>

                        <property name="educations">

                                    <map>

                                                <entry key="degree" value="BE"/>

                                                <entry key="post-degree" value="ME"/>

                                    </map>

                        </property>

                        <property name="projects">

                                    <props>

                                                <prop key="mini1">citi</prop>

                                                <prop key="mini2">hdfc</prop>

                                    </props>

                        </property>

            </bean>

 

 

            <bean id="e1" class="com.lara.Employee" autowire="constructor">

                        <constructor-arg name="firstName" value="Vijay"/>

                        <constructor-arg name="age" value="22"/>

                        <constructor-arg name="weight" value="45.9"/>

                        <constructor-arg name="marks">

                                    <list>

                                                <value>48</value>

                                                <value>78</value>

                                                <value>85</value>

                                    </list>

                        </constructor-arg>                      

                        <constructor-arg name="mails">

                                    <list>

                                                <value>a@a.com</value>

                                                <value>b@b.com</value>

                                                <value>c@c.om</value>

                                    </list>

                        </constructor-arg>

                        <constructor-arg name="subjects">

                                    <list>

                                                <value>maths</value>

                                                <value>cse</value>

                                                <value>english</value>

                                    </list>

                        </constructor-arg>

                        <constructor-arg name="mobileNos">

                                    <set>

                                                <value>9845098450</value>

                                                <value>9845098451</value>

                                                <value>9845098452</value>

                                    </set>

                        </constructor-arg>

                        <constructor-arg name="educations">

                                    <map>

                                                <entry key="degree" value="BE"/>

                                                <entry key="post-degree" value="ME"/>

                                    </map>

                        </constructor-arg>

                        <constructor-arg name="projects">

                                    <props>

                                                <prop key="mini1">citi</prop>

                                                <prop key="mini2">hdfc</prop>

                                    </props>

                        </constructor-arg>

            </bean>

 

 

 

</beans>       

Sunday(15-01-2017)

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.core.io.ClassPathResource;

 

public class Manager1

{

            public static void main(String[] args)

            {

                        ClassPathResource resource = new ClassPathResource("beans.xml");

                        BeanFactory beanFactory = new XmlBeanFactory(resource);

                        System.out.println("beanFactory is ready");

                        Person obj = (Person) beanFactory.getBean("p1");

                        System.out.println("Person object is ready");

                        System.out.println(obj.getFirstName());

                        System.out.println(obj.getLastName());

            }

}

package com.lara;

 

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import org.springframework.core.io.ClassPathResource;

 

public class Manager2

{

            public static void main(String[] args)

            {

                        ClassPathXmlApplicationContext context =

                                                new ClassPathXmlApplicationContext("beans.xml");

                        System.out.println("App context is ready");

                        Person obj = (Person) context.getBean("p1");

                        System.out.println("Person object is ready");

                        System.out.println(obj.getFirstName());

                        System.out.println(obj.getLastName());

                        System.out.println("------");

                        context.registerShutdownHook();

                        System.out.println("end");

            }

}

package com.lara;

 

import org.springframework.beans.factory.config.BeanDefinition;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;

import org.springframework.beans.factory.support.BeanDefinitionReader;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;

import org.springframework.beans.factory.xml.BeanDefinitionDecorator;

import org.springframework.context.ApplicationContext;

import org.springframework.context.ConfigurableApplicationContext;

import org.springframework.context.support.AbstractXmlApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

 

public class Manager3

{

            public static void main(String[] args)

            {

                        ClassPathXmlApplicationContext context =

                                                new ClassPathXmlApplicationContext("beans.xml");

                        System.out.println("App context is ready");

                        Person obj = (Person) context.getBean("p1");

                        System.out.println("Person object is ready");

                        System.out.println(obj.getFirstName());

                        System.out.println(obj.getLastName());

                        System.out.println("------");

                        BeanDefinitionRegistry factory =

                        (BeanDefinitionRegistry) context.getAutowireCapableBeanFactory();

                        factory.removeBeanDefinition("p1");

                        System.out.println("end");

            }

}

package com.lara;

 

import org.springframework.beans.factory.DisposableBean;

import org.springframework.beans.factory.InitializingBean;

 

public class Person //implements InitializingBean, DisposableBean

{

            private String firstName;

            private String lastName;

           

            public Person()

            {

                        System.out.println("Person");

            }

           

            public void setFirstName(String firstName)

            {

                        System.out.println("setFirstName");

                        this.firstName = firstName;

            }

           

            public void setLastName(String lastName)

            {

                        System.out.println("setLastName");

                        this.lastName = lastName;

            }

           

            public String getFirstName()

            {

                        return firstName;

            }

           

            public String getLastName()

            {

                        return lastName;

            }

           

           

            public void initMethod() throws Exception

            {

                        System.out.println("from initMethod");

            }

           

           

            public void destroyMethod() throws Exception

            {

                        System.out.println("from destroyMethod");

            }

           

}

beans.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans.xsd">

        <bean id="p1"

              class="com.lara.Person"

              init-method="initMethod"

              destroy-method="destroyMethod">

            <property name="firstName" value="abc"/>

            <property name="lastName" value="xyz"/>

        </bean>

</beans>       

  Saturday(21-01-2017)                 app5

package com.lara;

 

import org.springframework.context.support.ClassPathXmlApplicationContext;

 

public class Manager4

{

            public static void main(String[] args)

            {

                        ClassPathXmlApplicationContext context =

                                                new ClassPathXmlApplicationContext("beans.xml");

                        Student st1 = (Student) context.getBean("s1");

                        System.out.println(st1.getFirstName());

                        System.out.println(st1.getLastName());

            }

}

package com.lara;

 

import org.springframework.context.support.ClassPathXmlApplicationContext;

 

public class Manager5

{

            public static void main(String[] args)

            {

                        ClassPathXmlApplicationContext context =

                                                new ClassPathXmlApplicationContext("beans.xml");

                        Student st1 = (Student) context.getBean("s2");

                        System.out.println(st1.getFirstName());

                        System.out.println(st1.getLastName());

            }

}

package com.lara;

 

import org.springframework.context.support.ClassPathXmlApplicationContext;

 

public class Manager6

{

            public static void main(String[] args)

            {

                        ClassPathXmlApplicationContext context =

                                                new ClassPathXmlApplicationContext("beans.xml");

                        Student st1 = (Student) context.getBean("s3");

                        System.out.println(st1.getFirstName());

                        System.out.println(st1.getLastName());

            }

}

package com.lara;

 

import org.springframework.context.support.ClassPathXmlApplicationContext;

 

public class Manager7

{

            public static void main(String[] args)

            {

                        ClassPathXmlApplicationContext context =

                                                new ClassPathXmlApplicationContext("beans.xml");

                        Student st1 = (Student) context.getBean("s4");

                        System.out.println(st1.getFirstName());

                        System.out.println(st1.getLastName());

            }

}

package com.lara;

 

public class Student

{

            private String firstName;

            private String lastName;

           

            public void setFirstName(String firstName)

            {

                        this.firstName = firstName;

            }

           

            public String getFirstName()

            {

                        return firstName;

            }

           

            public void setLastName(String lastName)

            {

                        this.lastName = lastName;

            }

           

            public String getLastName()

            {

                        return lastName;

            }

}

beans.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans.xsd">

<!--         <bean id="p1"  -->

<!--                   class="com.lara.Person"  -->

<!--                   init-method="initMethod" -->

<!--                   destroy-method="destroyMethod"> -->

<!--                 <property name="firstName" value="abc"/> -->

<!--                 <property name="lastName" value="xyz"/> -->

<!--         </bean> -->

        <bean id="s1" class="com.lara.Student">

            <property name="firstName" value="abc"/>

            <property name="lastName" value="xyz"/>

        </bean>

        <bean id="s2" parent="s1">

            <property name="firstName" value="hello"/>

        </bean>     

       

        <bean id="s3" class="com.lara.Student" abstract="true">

            <property name="firstName" value="test"/>

            <property name="lastName" value="xyz"/>

        </bean>

       

        <bean id="s4" parent="s3">

            <property name="lastName" value="Vijay"/>

        </bean>

       

       

       

       

       

</beans>       

app6

package com.lara;

 

import org.springframework.context.support.ClassPathXmlApplicationContext;

 

public class Util

{

            private static ClassPathXmlApplicationContext context;

           

            static

            {

                        context = new ClassPathXmlApplicationContext("config.xml");

            }

           

            public static Object getBean(String id)

            {

                        return context.getBean(id);

            }

}

package com.lara;

 

public class Address

{

            private String houseNo;

            private String streetName;

            public String getHouseNo()

            {

                        return houseNo;

            }

            public void setHouseNo(String houseNo)

            {

                        this.houseNo = houseNo;

            }

            public String getStreetName()

            {

                        return streetName;

            }

            public void setStreetName(String streetName)

            {

                        this.streetName = streetName;

            }

           

           

}

package com.lara;

 

public class Manager1

{

            public static void main(String[] args)

            {

                        Person p1 = (Person) Util.getBean("p1");

                        System.out.println(p1.getFirstName());

                        System.out.println(p1.getLastName());

                        System.out.println(p1.getAddress().getHouseNo());

                        System.out.println(p1.getAddress().getStreetName());

            }

}

package com.lara;

 

public class Manager2

{

            public static void main(String[] args)

            {

                        Employee p1 = (Employee) Util.getBean("e1");

                        System.out.println(p1.getFirstName());

                        System.out.println(p1.getLastName());

                        System.out.println(p1.getAddress().getHouseNo());

                        System.out.println(p1.getAddress().getStreetName());

            }

}

package com.lara;

 

import javax.annotation.Resource;

 

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Qualifier;

 

public class Person

{

            private String firstName;

            private String lastName;

            private Address address;

            public String getFirstName()

            {

                        return firstName;

            }

            public void setFirstName(String firstName)

            {

                        this.firstName = firstName;

            }

            public String getLastName()

            {

                        return lastName;

            }

            public void setLastName(String lastName)

            {

                        this.lastName = lastName;

            }

            public Address getAddress()

            {

                        return address;

            }

           

            @Resource(name="a1")

            public void setAddress(Address address)

            {

                        this.address = address;

            }

           

           

}

package com.lara;

 

import javax.annotation.Resource;

 

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Qualifier;

 

public class Employee

{

            private String firstName;

            private String lastName;

           

 

            private Address address;

           

           

            public Employee(String firstName, String lastName,

                                                                       

                                    Address address)

            {

                        this.firstName = firstName;

                        this.lastName = lastName;

                        this.address = address;

            }

           

            public String getFirstName()

            {

                        return firstName;

            }

           

            public String getLastName()

            {

                        return lastName;

            }

           

            public Address getAddress()

            {

                        return address;

            }

}

config.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns:context="http://www.springframework.org/schema/context"

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

    <context:annotation-config/>

            <bean id="a1" class="com.lara.Address">

                        <property name="houseNo" value="123/B"/>

                        <property name="streetName" value="BTM"/>

            </bean>

            <bean id="a2" class="com.lara.Address">

                        <property name="houseNo" value="123/C"/>

                        <property name="streetName" value="JP Nagar"/>

            </bean>       

            <bean id="p1" class="com.lara.Person">

                        <property name="firstName" value="abc"/>

                        <property name="lastName" value="xyz"/>

            </bean>

            <bean id="e1" class="com.lara.Employee">

                        <constructor-arg name="firstName" value="abc"/>

                        <constructor-arg name="lastName" value="xyz"/>

            </bean>

</beans>