package org.zcs.spring;publicclassTriangleimplementsShape{private Point pointA;private Point pointB;private Point pointC;public Point getPointA(){return pointA;}publicvoidsetPointA(Point pointA){this.pointA = pointA;}public Point getPointB(){return pointB;}publicvoidsetPointB(Point pointB){this.pointB = pointB;}public Point getPointC(){return pointC;}publicvoidsetPointC(Point pointC){this.pointC = pointC;}publicvoid draw (){
System.out.println("Drawing Triangle :");
System.out.println("This is PointA: ("+pointA.getX()+","+ pointA.getY()+")");
System.out.println("This is PointB: ("+pointB.getX()+","+ pointB.getY()+")");
System.out.println("This is PointC: ("+pointC.getX()+","+ pointC.getY()+")");}}
DrawingApp.java
package org.zcs.spring;import org.springframework.beans.factory.BeanFactory;import org.springframework.context.ApplicationContext;import org.springframework.context.support.AbstractApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.context.support.FileSystemXmlApplicationContext;publicclassDrawingApp{publicstaticvoidmain(String[] args){// TODO Auto-generated method stub//BeanFactory factory = new FileSystemXmlApplicationContext("src/spring.xml");//Triangle triangle = new Triangle();
ApplicationContext context =newClassPathXmlApplicationContext("spring.xml");
Shape circle =(Shape)context.getBean("triangle");
circle.draw();}}
Circle.java
package org.zcs.spring;publicclassCircleimplementsShape{private Point center;public Point getCenter(){return center;}publicvoidsetCenter(Point center){this.center = center;}@Overridepublicvoiddraw(){// TODO Auto-generated method stub
System.out.println("Drawing Circle:");
System.out.println("Circle : point is : "+ center.getX()+","+ center.getY());}}
spring.xml
<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"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">
<bean id = "triangle" class= "org.zcs.spring.Triangle" autowire= "byName" >
<property name="pointA" ref = "pointA"></property>
<property name="pointB" ref = "pointB"></property>
<property name="pointC" ref = "pointC"></property></bean>
<bean id= "pointA" class = "org.zcs.spring.Point">
<property name="x" value = "${pointA.pointX}"></property>
<property name="y" value = "${pointA.pointY}"></property></bean>
<bean id= "pointB" class = "org.zcs.spring.Point">
<property name="x" value = "20"></property>
<property name="y" value = "0"></property></bean>
<bean id= "pointC" class = "org.zcs.spring.Point">
<property name="x" value = "0"></property>
<property name="y" value = "20"></property></bean>
<bean class = "org.zcs.spring.MyBeanFactory" ></bean>
<bean class = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value = "pointsconfig.properties"></property></bean>
<bean id = "circle" class= "org.zcs.spring.Circle" >
<property name="center" ref = "pointA"></property></bean></beans>
1.Coding To InterfacesShape.javapackage org.zcs.spring;public interface Shape { public void draw();}Triangle.javapackage org.zcs.spring; public class Triangle implements Shape {...