FactoryBean的使用详解...
来源:互联网 发布:浙江堂鼓网络 编辑:程序博客网 时间:2024/04/29 04:49
<strong><span style="font-size:14px;">package com.spring.factory2;public class Car2 {private int brand;private double price;public Car2(int brand,double price){this.price = price;this.brand = brand;}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;}@Overridepublic String toString() {return "Car [brand=" + brand + ", price=" + price + "]";}}</span></strong>
package com.spring.factory2;import org.springframework.beans.factory.FactoryBean;public class CarFactoryBean implements FactoryBean<Car2>{private int brand;public void setBrand(int brand) {this.brand = brand;}public Car2 getObject() throws Exception {return new Car2(brand,8999);}public Class<?> getObjectType() {return Car2.class;}public boolean isSingleton() {return true;}}
<?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: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="car2" class="com.spring.factory2.CarFactoryBean"><property name="brand" value="1000000000"></property></bean></beans>
package com.spring.factory2;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-factory2.xml");Car2 car = (Car2)appContext.getBean("car2");System.out.println(car);}}
0 0
- FactoryBean的使用详解...
- Spring的FactoryBean详解
- FactoryBean的使用
- Spring的FactoryBean使用
- FactoryBean的使用
- BeanFactory 与 FactoryBean的区别及FactoryBean详解
- InitializingBean,FactoryBean详解
- FactoryBean,InitializingBean使用
- Spring FactoryBean,InitializingBean使用
- Spring FactoryBean接口使用
- 如何使用Spring FactoryBean?
- bean的加载(二) FactoryBean的使用
- Spring学习笔记 关于FactoryBean接口的使用
- 使用 FactoryBean 让你的 spring 配置动起来
- 使用Spring的FactoryBean创建同步队列线程池
- 使用FactoryBean定制bean的实例化逻辑
- spring源码附录(4)FactoryBean的使用
- FactoryBean的工作方式
- 【虫师--系列10】cookie、session、sessionid 与jsessionid
- 内容对齐 TextAlignment & VerticalAlignment & HorizontalAlignment & contentMode
- JSP浏览商品信息项目学习笔记
- 请注释你那该死的代码
- Linux下chkconfig命令详解
- FactoryBean的使用详解...
- Dubbo入门示例
- 卸载Oracle
- java复习并发
- 关于max_allowed_packet的修改,以及修改后总是自动重置1024
- SQL语句的学习
- 逼自己一把,你就优秀了
- tnsping openview;
- yum升级php