BeanPostProcessor and static BeanFactory Create
来源:互联网 发布:新站优化方案 编辑:程序博客网 时间:2024/04/29 03:28
<span style="font-size:18px;">package com.spring.factory;public class Car {private int brand;private double price;public Car(){System.out.println("Construct car create..");}public Car(double price){System.out.println("Construct car(price) create..");this.price = price;}public int getBrand() {return brand;}public void setBrand(int brand) {this.brand = brand;}public double getPrice() {return price;}public void setPrice(double price) {this.price = price;}public void init(){System.out.println("car bean init()...");}public void destory(){System.out.println("car bean destory()...");}@Overridepublic String toString() {return "Car [brand=" + brand + ", price=" + price + "]";}}</span>
<span style="font-size:18px;"></span>
<span style="font-size:18px;"></span><pre name="code" class="java">package com.spring.factory;import java.util.HashMap;import java.util.Map;public class InstanceFactory {private Map<String ,Car> carMap = null;public InstanceFactory(){carMap = new HashMap<String ,Car>();carMap.put("BMW", new Car(5622));carMap.put("aodi", new Car(2000));}public Car getCarByName(String name){return carMap.get(name);}}
package com.spring.factory;import org.springframework.beans.BeansException;import org.springframework.beans.factory.config.BeanPostProcessor;public class MyBeanPostProcessor implements BeanPostProcessor{public Object postProcessAfterInitialization(Object bean, String arg1)throws BeansException {System.out.println("postProcessAfterInitialization"+bean+","+arg1);Car car = (Car)bean;car.setBrand(1);car.setPrice(1000);return bean;}public Object postProcessBeforeInitialization(Object bean, String arg1)throws BeansException {System.out.println("postProcessBeforeInitialization"+bean+","+arg1);return bean;}}
package com.spring.factory;import java.util.HashMap;import java.util.Map;public class StaticFactoryBean {private static Map<String ,Car> carMap = new HashMap<String ,Car>();static{System.out.println("StaticFactoryBean init static");carMap.put("BMW", new Car(5622));carMap.put("aodi", new Car(2000));}public static Car getCarByName(String name){return carMap.get(name);}}
package com.spring.factory;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Test {public static void main(String[] args) {ApplicationContext appContext = new ClassPathXmlApplicationContext("beans-factory.xml");Car car = (Car)appContext.getBean("car");System.out.println("main:"+car);System.out.println("-------关闭Application--------");ClassPathXmlApplicationContext appContext2 = (ClassPathXmlApplicationContext)appContext;appContext2.close();}}
0 0
- BeanPostProcessor and static BeanFactory Create
- 【Spring4揭秘 BeanFactory】修改Bean---BeanPostProcessor
- create and use win32 static library
- BeanFactory and ServletContext
- Siebel Tools: Create new LOV Type and Values & Create Static Picklist Using Tools
- beanPostProcessor
- BeanPostProcessor
- BeanPostProcessor
- How to create, develop, and distribute iOS Static Frameworks quickly and efficiently
- BeanFactory and ApplicationContext in Spring
- c static libarary create
- BeanFactory
- BeanFactory
- BeanFactory
- BeanFactory
- mysql create and grant
- Create PDS and Member
- Create Tables and Constraints
- Linux 下压缩与解压.zip和.rar及.7z文件
- 数组和集合区别
- iOS笔记链接
- 做北京linux培训哪家靠谱
- 欢迎使用CSDN-markdown编辑器
- BeanPostProcessor and static BeanFactory Create
- Google SRE (DevOps)
- 不只是给面试加分 -- Java WeakReference的理解与使用
- SAP MM移动类型概念详述
- Eclipse Junit测试报initializationError错误
- windows和linux 下将tomcat注册为服务
- XMLHttpRequest对象解决中文乱码问题
- JVM Tool Interface JVM工具接口
- Unity3D -- 使用可移动图片作为3D背景