spring学习笔记(2)

来源:互联网 发布:网络身份认证系统 编辑:程序博客网 时间:2024/05/16 04:50

spring对单态模式和工厂模式的实现

package com.szlongtu.xz;import org.springframework.context.ApplicationContext;import org.springframework.context.support.FileSystemXmlApplicationContext;public class SpringTest {public static void main(String[] args) {ApplicationContext ctx=new FileSystemXmlApplicationContext("spring.xml");Person p = null;p=(Person)ctx.getBean("chinese");System.out.println(p.sayHello("wawa"));System.out.println(p.sayGoodBye("wawa"));p=(Person)ctx.getBean("american");System.out.println(p.sayHello("wawa"));System.out.println(p.sayGoodBye("wawa"));}}

<?xml version="1.0" encoding="gb2312"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN""http://www.springframework.org/dtd/spring-beans.dtd"><beans><bean id="chinese" class="com.szlongtu.xz.Chinese"/><bean id="american" class="com.szlongtu.xz.American"/></beans>
郁闷了照着书写的,调试报错,不知错哪儿,但是工厂模式和单态模式应该是懂了。

0 0
原创粉丝点击