spring静态工厂实例化
来源:互联网 发布:microsoft fix it卸载 编辑:程序博客网 时间:2024/05/01 14:50
搭建环境同上
1---在src/resource下加入-----applicationContext-web.xml
<?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="beanFactory" class="com.neusoft.test.spring.factory.BeanFactory" factory-method="createFormat" /></beans>
2---在src/java下加入
四个包 factory format impl main
1------- 在factory中加入 -----BeanFactory.java
package com.neusoft.test.spring.factory;import com.neusoft.test.spring.format.Format;import com.neusoft.test.spring.format.impl.LowerFormat;public class BeanFactory {public static Format createFormat(){return new LowerFormat();}}
2------- 在format 中加入 -----Format.java
package com.neusoft.test.spring.format;public interface Format { String format(String text);}
3------- 在impl中加入 -----LowerFormat.java
package com.neusoft.test.spring.format.impl;import com.neusoft.test.spring.format.Format;public class LowerFormat implements Format {public String format(String text) {return text.toLowerCase();}}
4------- 在main中加入 -----Test.java
package com.neusoft.test.spring.main;import com.neusoft.test.spring.format.impl.LowerFormat;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Test {public static void main(String[] args) {//静态工厂实例化ApplicationContext applicationContext=new ClassPathXmlApplicationContext(new String("applicationContext-web.xml"));LowerFormat lowerFormat=(LowerFormat)applicationContext.getBean("beanFactory");System.out.println(lowerFormat.format("abcABC"));}}
- spring静态工厂实例化
- Spring 静态工厂和实例工厂
- Spring 使用静态工厂方式实例化Bean
- 使用Spring(二)实例化方式(静态工厂,实例工厂)
- spring 静态工厂 &实例工厂实例方法 & 实现factorybean接口
- Spring的实例工厂方法和静态工厂方法
- spring的静态工厂和实例工厂方法
- Spring的实例工厂方法和静态工厂方法
- spring实例化bean之简单工厂静态方法实例化
- spring中通过静态工厂方法获取bean实例化对象
- Junit测试一个spring静态工厂实例化bean的例子,出现java.lang.IllegalArgumentException异常。
- spring 9 bean配置--通过工厂方法(静态工厂方法&实例工厂方法
- spring实例工厂,静态工厂以及写有工厂方法的程序
- fragment实例化方法(用静态工厂)
- 静态工厂实例代码
- spring静态工厂
- Spring Bean工厂创建Bean实例的方法之使用静态工厂类
- Spring学习之使用静态工厂方法以及实例工厂方法配置bean
- How to uncompress files with suffix tar.xz
- C#入门经典第一章
- 使用HTML5的canvas做一个会动的时钟
- MySQL学习笔记(二)架构组成
- <<虞美人--加班>>,献给每天都在加班的IT人
- spring静态工厂实例化
- mkdir与cd命令合并
- 两种高性能I/O设计模式(Reactor/Proactor)的比较
- HDU 1412 ( {A} + {B} )
- /etc/yum.repos.d/CentOS-Base.repo
- Android开发之自定义View(视图)
- VMware 配置linux后出现提示:Failed to initialize remote display subsystem
- 用iis发布网站(转)
- 银行业务调度系统 学习笔记