<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="triangle" class="zxl.Triangle" >
<property name="pointA" ref="pointA" />
<property name="pointB" ref="pointB" />
<property name="pointC" ref="pointC" />
</bean>
<bean id="pointA" class="zxl.Point" >
<property name="x" value="${pointA.pointX}" />
<property name="y" value="${pointA.pointY}" />
</bean>
<bean id="pointB" class="zxl.Point" >
<property name="x" value="-20" />
<property name="y" value="0" />
</bean>
<bean id="pointC" class="zxl.Point" >
<property name="x" value="20" />
<property name="y" value="0" />
</bean>
<bean class="zxl.MyBeanFactoryPP" />
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name="locations" value="pointsconfig.peoperties" ></property>
</bean>
</beans>
package zxl;
import java.util.List;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class Triangle {
private Point pointA;
private Point pointB;
private Point pointC;
public Point getPointA() {
return pointA;
}
public void setPointA(Point pointA) {
this.pointA = pointA;
}
public Point getPointB() {
return pointB;
}
public void setPointB(Point pointB) {
this.pointB = pointB;
}
public Point getPointC() {
return pointC;
}
public void setPointC(Point pointC) {
this.pointC = pointC;
}
public void draw(){
System.out.println("point A ("+getPointA().getX()+","+getPointA().getY()+")");
System.out.println("point B ("+getPointB().getX()+","+getPointB().getY()+")");
System.out.println("point C ("+getPointC().getX()+","+getPointC().getY()+")");
}
}
package zxl;
public class Point {
private int x;
private int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
package zxl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class DrawingApp {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context=new ClassPathXmlApplicationContext("spring.xml");
Triangle triangle =(Triangle) context.getBean("triangle");
triangle.draw();
}
}
package zxl;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
public class DisplayNameBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
// TODO Auto-generated method stub
System.out.println("in after initialization method bean name is "+beanName);
return bean;
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
// TODO Auto-generated method stub
System.out.println("in before initialization method bean name is "+beanName);
return bean;
}
}
package zxl;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
public class MyBeanFactoryPP implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory arg0) throws BeansException {
// TODO Auto-generated method stub
System.out.println("my bean factory post processor is called");
}
}
pointsconfig.peoperties
pointA.pointX=0
pointA.pointY=0