??xml version="1.0" encoding="utf-8" standalone="yes"?>中文精品在线,福利视频在线导航,极品少妇一区二区三区精品视频 http://www.aygfsteel.com/tianya0801/category/29660.htmlQ是一U境? zh-cn Wed, 16 Apr 2008 15:13:37 GMT Wed, 16 Apr 2008 15:13:37 GMT 60 JSON入门 http://www.aygfsteel.com/tianya0801/archive/2008/04/15/193161.html未知数据 未知数据 Tue, 15 Apr 2008 09:23:00 GMT http://www.aygfsteel.com/tianya0801/archive/2008/04/15/193161.html http://www.aygfsteel.com/tianya0801/comments/193161.html http://www.aygfsteel.com/tianya0801/archive/2008/04/15/193161.html#Feedback 0 http://www.aygfsteel.com/tianya0801/comments/commentRss/193161.html http://www.aygfsteel.com/tianya0801/services/trackbacks/193161.html
1.json?br />
json(JavaScript Object Notation)是一U轻量的数据交换格?采用?font color="#ff0000">~程语言无关的文本格?/font>,可替换XML成ؓAJAXE序中的数据交换格式.
ob是一个字W串,如果把这个字W串赋值给一个javascript的变?那么该变量就成ؓ一个对象的引用,而这个对象就是用q个字符串所构徏出来?/p>
2.json对象
<script type="text/javascript">
var ob = {"name":"wang","age":25,"email":"test@test.com.cn "};
alert(ob.name);
</script>
对象是属性、值对的集合。一个对象的开始于“{”Q结束于“}”。每一个属性名和值间?#8220;:”提示Q属性间?#8220;,”分隔?
{"name":"wang","age":25,"email":"test@test.com.cn "};
{"name":{"firstName":"wang","lastName":"ning"},"age":25,"email":"test@test.com.cn "};
数组是有序的值的集合。一个数l开始于"["Q结束于"]"Qg间用","分隔?
[{"name":"wang","age":25},{"name":"zhang","age":27}]
值可以是引号里的字符丌Ӏ数字、true、false、nullQ也可以是对象或数组。这些结构都?strong>嵌套?
字符串和数字的定义和C或Java基本一致?/li>
3.xml与json的{?/div>
<contact>
<friend>
<name>Michael</name>
<email>17bity@gmail.com</email>
<homepage>http://www.jialing.net</homepage>
</friend>
<friend>
<name>John</name>
<email>john@gmail.com</email>
<homepage>http://www.john.com</homepage>
</friend>
<friend>
<name>Peggy</name>
<email>peggy@gmail.com</email>
<homepage>http://www.peggy.com</homepage>
</friend>
</contact>
]]>
一个很有意思的IOC介绍 http://www.aygfsteel.com/tianya0801/archive/2008/03/03/183407.html未知数据 未知数据 Mon, 03 Mar 2008 03:08:00 GMT http://www.aygfsteel.com/tianya0801/archive/2008/03/03/183407.html http://www.aygfsteel.com/tianya0801/comments/183407.html http://www.aygfsteel.com/tianya0801/archive/2008/03/03/183407.html#Feedback 0 http://www.aygfsteel.com/tianya0801/comments/commentRss/183407.html http://www.aygfsteel.com/tianya0801/services/trackbacks/183407.html
介绍 IOCQ{Q?
作者:C icecloud(AT)sina.com BLOG: http://icecloud.51.net 旉Q?004.02.15
版权声明Q本文由C完成Q首发于CSDNQ作者保留中文版权。未l许可,不得使用于Q何商业用途。欢q{载,但请保持文章及版权声明完整。如需联络请发邮gQicecloud(AT)sina.com
一、IOC
IoC是Inversion of ControlQ控制反转。在Java开发中QIoC意味着你设计好的cMl系l去控制Q而不是在你的cd部控制。这UCؓ控制反{?
下面我们以几个例子来说明什么是IoC。假设我们要设计一个Girl和一个Boyc,其中Girl有kissҎQ即Girl惌Kiss一个Boy。那么,我们的问题是QGirl如何能够认识q个BoyQ?br />
在我们中国,常见的Q与GG的认识方式有以下几种Q?青梅竚wQ?亲友介绍Q?父母包办?那么哪一U才是最好呢Q?br />
青梅竚wQGirl从小q道自qBoy?
public class Girl {
void kiss(){
Boy boy = new Boy();
}
}
然而从开始就创徏的Boy~点是无法在更换。ƈ且要负责Boy的整个生命周期。如果我们的Girl惌换一个怎么办?Q笔者严重不支持Girll常更换BoyQ?
亲友介绍Q由中间责提供Boy来见?br />
public class Girl {
void kiss(){
Boy boy = BoyFactory.createBoy();
}
}
亲友介绍Q固然是好。如果不满意Q尽另外换一个好了。但是,亲友BoyFactoryl常是以Singleton的Ş式出玎ͼ不然是Q存在于GlobalsQ无处不在,无处不能。实在是太繁琐了一点,不够灉|。我Z么一定要q个亲友掺和q来呢?Z么一定要付给她介l费呢?万一最好的朋友׃了我的男朋友呢?
父母包办Q一切交l父母,自己不用费吹C力,只需要等着Kiss好了?br />
public class Girl {
void kiss(Boy boy){
// kiss boy
boy.kiss();
}
}
WellQ这是对Girl最好的ҎQ只要想办法贿赂了Girl的父母,q把Boy交给他。那么我们就可以L的和Girl来Kiss了。看来几千年传统的父母之命还真是有用哦。至Boy和Girl不用自己瞎忙乎了?br />
q就是IOCQ将对象的创建和获取提取到外部。由外部容器提供需要的lg?
我们知道好莱坞原则:“Do not call us, we will call you.” 意思就是,You, girlie, do not call the boy. We will feed you a boy?
我们q应该知道依赖倒{原则?Dependence Inversion PrincinpleQDIP。Eric Gamma_要面向抽象编E。面向接口编E是面向对象的核心?/p>
lg应该分ؓ两部分,即Service, 所提供功能的声明Implementation, Service的实现好处是Q多实现可以L切换Q防?“everything depends on everything” 问题Q即具体依赖于具体?br />
所以,我们的Boy应该是实现Kissable接口。这样一旦Girl不想kiss可恶的Boy的话Q还可以kiss可爱的kitten和慈的grandmother?br />
二、IOC的type
IoC的Type指的是Girl得到Boy的几U不同方式。我们逐一来说明?
IOC type 0Q不用IOC
public class Girl implements Servicable {
private Kissable kissable;
public Girl() {
kissable = new Boy();
}
public void kissYourKissable() {
kissable.kiss();
}
}
Girl自己建立自己的BoyQ很难更换,很难׃nl别人,只能单独使用Qƈ负责完全的生命周期?br />
IOC type 1Q先看代码:
public class Girl implements Servicable {
Kissable kissable;
public void service(ServiceManager mgr) {
kissable = (Kissable) mgr.lookup(“kissable”);
}
public void kissYourKissable() {
kissable.kiss();
}
}
q种情况出现于Avalon Framework。一个组件实CServicable接口Q就必须实现serviceҎQƈ传入一个ServiceManager。其中会含有需要的其它lg。只需要在serviceҎ中初始化需要的Boy。另外,J2EE中从Context取得对象也属于type 1Q它依赖于配|文Ӟ
…
IOC type 2Q?br />
public class Girl {
private Kissable kissable;
public void setKissable(Kissable kissable) {
this.kissable = kissable;
}
public void kissYourKissable() {
kissable.kiss();
}
}
Type 2出现于Spring FrameworkQ是通过JavaBean的setҎ来将需要的Boy传递给Girl。它必须依赖于配|文件?br />
IOC type 3
public class Girl {
private Kissable kissable;
public Girl(Kissable kissable) {
this.kissable = kissable;
}
public void kissYourKissable() {
kissable.kiss();
}
}
q就是PicoContainer的组?。通过构造函C递BoylGirl?br />
PicoContainer container = new DefaultPicoContainer();
container.registerComponentImplementation(Boy.class);
container.registerComponentImplementation(Girl.class);
Girl girl = (Girl) container.getComponentInstance(Girl.class);
girl.kissYourKissable();
Q注Q全文完Q后面作者语和文章参考资料)
作者语Q?
WellQ以上的q些理论部分有些已经有了新的定义了。过些天我会再写一些文章具体说明。比如,原来的三Utypel构现在已经重新定义Z赖注的许多层次?br />
IoC很年轻,q在发展。伴随着IOC的发展,AOPQCOPQSOP{等都在不断的发展。作为程序员Q随时关注着新的思想的发展是一件很L愉快的事情。有没有人愿意和我一h讨学习共同进步呀Q?
参考资?br />
1 本文主要插图及文字来源于ThoughtWorks公司的Jon Tirsén ?Aslak HellesøyQPicoContainer的两位开发者)Q?003q在Java Polis的演讲PPT。有删改?br />
http://www.picocontainer.org/presentations/JavaPolis2003.ppt
http://www.picocontainer.org/presentations/JavaPolis2003.pdf
2 DIPQ?Robert C Martin, Bob大叔的优U论文
http://www.objectmentor.com/resources/articles/dip.pdf
3 Dependency Injection 依赖注射QMatrin Fowler对DIP的扩?br />
http://www.martinfowler.com/articles/injection.html
4 IOC框架
PicoContainer 优秀的IOC框架
http://picocontainer.org/
Avalon
http://avalon.apache.org/
Spring Framework
http://www.springframework.org/
HiveMind
http://jakarta.apache.org/commons/hivemind
5 中文资料
E序匠:国内研究Pico的先?br />
http://douleimi.vicp.net/space/start
JdonQ板桥也在研I?br />
http://www.jdon.com/design.htm
Spring Framework中文论坛
http://xglw.51.net/5team/springframework/index.php
Avalon 中文资料
http://www.huihoo.org/apache/avalon/introduction.html
ERPROAD
http://www.erproad.org/index.asp?vt=bycat&cat_id=37
Open Heart
http://blogbus.com/blogbus/blog/index.php?blogid=2529&cat=5
]]> spring2.0--使用模板装配 http://www.aygfsteel.com/tianya0801/archive/2008/02/29/182957.html未知数据 未知数据 Fri, 29 Feb 2008 08:02:00 GMT http://www.aygfsteel.com/tianya0801/archive/2008/02/29/182957.html http://www.aygfsteel.com/tianya0801/comments/182957.html http://www.aygfsteel.com/tianya0801/archive/2008/02/29/182957.html#Feedback 0 http://www.aygfsteel.com/tianya0801/comments/commentRss/182957.html http://www.aygfsteel.com/tianya0801/services/trackbacks/182957.html 使用模板装配
如果需要装配大量的同一cd的Bean,而这些Bean都有一些相同的属?可以使用模板来装配Bean.
package example.chapter3;
import java.io.Serializable;
public class Employee implements Serializable {
private String name; private String title; private String company; private String department;
public String getName() { return name; } public void setName(String name) { this.name = name; }
public String getTitle() { return title; } public void setTitle(String title) { this.title = title; }
public String getCompany() { return company; } public void setCompany(String company) { this.company = company; }
public String getDepartment() { return department; } public void setDepartment(String department) { this.department = department; }
}
xml配置文g
<bean id="abstractEmployee" class="java.io.Serializable" abstract ="true"> <property name="company" value="Inc." /> <property name="department" value="Center" /> </bean>
<bean id="engineer1" class="example.chapter3.Employee" parent ="abstractEmployee"> <property name="name" value="Bill" /> <property name="title" value="Software Engineer" /> </bean>
<bean id="engineer2" class="example.chapter3.Employee" parent="abstractEmployee"> <property name="name" value="Steven" /> <property name="title" value="Hardware Engineer" /> </bean>
<bean id="manager" class="example.chapter3.Employee" parent="abstractEmployee"> <property name="name" value="Michael" /> <property name="title" value="Manager" /><property name="department" value="HR" /> </bean>
1.指定abstract="true"表示q个Bean只作为模板?Spring容器不会ҎCؓabstract的Bean创徏实例,也不会检查其属性是否合?因此可以随意注入M属?/div>
2.下面创徏的engineer1,engineer2,engineer3指定parent ="abstractEmployee,自动承abstractEmployee的company和department属?同时子类也可以覆盖模板中的属?比如engineer3
]]>
spring2.0--自动装配 http://www.aygfsteel.com/tianya0801/archive/2008/02/29/182880.html未知数据 未知数据 Fri, 29 Feb 2008 03:54:00 GMT http://www.aygfsteel.com/tianya0801/archive/2008/02/29/182880.html http://www.aygfsteel.com/tianya0801/comments/182880.html http://www.aygfsteel.com/tianya0801/archive/2008/02/29/182880.html#Feedback 0 http://www.aygfsteel.com/tianya0801/comments/commentRss/182880.html http://www.aygfsteel.com/tianya0801/services/trackbacks/182880.html spring2.0之自动装?/p>
Bar.java
Foo.java
SimpleTest.java
public class SimpleTest { private Foo foo; private Foo foo2; private Bar bar; public SimpleTest(){ } public SimpleTest(Foo foo, Bar bar) { System.out.println("constructor bar,foo call"); this.foo = foo; this.bar = bar; } public SimpleTest(Foo foo) { System.out.println("constructor foo call"); this.foo = foo; } public Bar getBar() { return bar; } public void setBar(Bar bar) { System.out.println("property bar set"); this.bar = bar; } public Foo getFoo() { return foo; } public void setFoo(Foo foo) { System.out.println("property foo set"); this.foo = foo; } public Foo getFoo2() { return foo2; } public void setFoo2(Foo foo2) { System.out.println("property foo2 set"); this.foo2 = foo2; } }
xml配置文g:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "
<beans> <!-- 定义foo和bar --> <bean id="foo" class="Foo"/> <bean id="bar" class="Bar"/> <!-- 使用ByName方式装配Q这U方式的原理是如果目标bean有一个名为foo的属性而bean工厂有一个同名的bean,则把q个bean装配l目标bean的属?Spring容器查找与SimpleTest属性名U?即foo和bar)相同的Bean,然后自动注入到该属性中,否则不会注入 --> <bean id="simpleTest1" class="SimpleTest" autowire="byName"/> <!-- 使用ByType方式装配,q种方式的原理是如果目标bean的属性类型和bean工厂中的一个bean的类型相府,则把q个bean装配l目标bean,如果对于一个相W,则出现异?Spring容器查找与SimpleTest属性的讑ր方法参数类?即Foo和Bar)兼容的Bean --> <bean id="simpleTest2" class="SimpleTest" autowire="byType"/> <!-- 使用constructor方式Q这U方式的原理是最大数量的匚w目标bean的构造方法,如果目标bean有一个String的构造方法,一个String和int的构造方?bean工厂中也有string和int两个bean,则spring会装配String和int的构造方?/span>
Spring容器试图找出所有与构造方法的参数cd兼容的Bean --> <bean id="simpleTest3" class="SimpleTest" autowire="constructor"/> <!-- 自动装配方式Q这U方式会自动在byType和Constructor中自动匹配,当目标bean有一个无参(本例Q构造方法是Qspring会选择使用byType方式 --> <bean id="simpleTest4" class="SimpleTest" autowire="autodetect"/> </beans>
试:
import java.io.File; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.FileSystemResource;
public class TestSpring { public static void main(String args[]) throws Exception{ //获取bean factory BeanFactory factory=(BeanFactory)getBeanFactory(); SimpleTest simpleTest=null; System.out.println("use byNameQ?); simpleTest=(SimpleTest)factory.getBean("simpleTest1"); System.out.println("use byTypeQ?); simpleTest=(SimpleTest)factory.getBean("simpleTest2"); System.out.println("use byContructorQ?); simpleTest=(SimpleTest)factory.getBean("simpleTest3"); System.out.println("use byAutoQ?); simpleTest=(SimpleTest)factory.getBean("simpleTest4"); } public static BeanDefinitionRegistry getBeanFactory() { //获取bean factory String realpath=""; //加蝲配置?br/>realpath=System.getProperty("user.dir")+File.separator+"src"+File.separator+File.separator+"beans.xml"; XmlBeanFactory factory=new XmlBeanFactory(new FileSystemResource(realpath)); return factory; } }
l果:
2008-2-29 10:26:04 org.springframework.core.CollectionFactory <clinit> 信息: JDK 1.4+ collections available 2008-2-29 10:26:04 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from file [D:\MyWork\AutoWire\src\beans.xml] use byNameQ?br/>property bar set property foo set property foo2 set use byTypeQ?br/>property bar set property foo set property foo2 set use byContructorQ?br/>constructor bar,foo call use byAutoQ?br/>property bar set property foo set property foo2 set
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1675871
]]> Spring2.0--配置工厂Bean http://www.aygfsteel.com/tianya0801/archive/2008/02/28/182652.html未知数据 未知数据 Thu, 28 Feb 2008 04:30:00 GMT http://www.aygfsteel.com/tianya0801/archive/2008/02/28/182652.html http://www.aygfsteel.com/tianya0801/comments/182652.html http://www.aygfsteel.com/tianya0801/archive/2008/02/28/182652.html#Feedback 0 http://www.aygfsteel.com/tianya0801/comments/commentRss/182652.html http://www.aygfsteel.com/tianya0801/services/trackbacks/182652.html 配置工厂Bean
通常由应用程序直接用new创徏新的对象,Z对象的创徏和用相分离,采用工厂模式,卛_用程序将对象的创建及初始化职责交l工厂对?
一般情况下,应用E序有自q工厂对象来创建bean.如果应用程序自q工厂对象交给Spring理,那么Spring理的就不是普通的bean,而是工厂Bean.
调用getBean()Ҏ,Springq回的不是直接创建的Bean的实?而是由工厂Bean创徏的Bean实例.
一般在Spring中配|工厂Bean,?中不同类型的工厂Bean的配|?
1.静态工?/span>
创徏具体Bean实例的是静态方?/span>
import java.util.Random;
public class StaticFactoryBean {
public static Integer createRandom() {
return new Integer(new Random().nextInt()); } }
其U_Spring容器来管?需要通过factory-method指定静态方法名U?/div>
<bean id="random" class="example.chapter3.StaticFactoryBean"factory-method="createRandom" //createRandomҎ必须是static?才能扑ֈ scope="prototype" />
试:
public static void main(String[] args) { XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("config.xml")); System.out.println(factory.getBean("random").toString());
//StaticFactoryBean sfb = (StaticFactoryBean)factory.getBean("random"); //System.out.println(sfb.createRandom().toString());
//调用getBean()?q回随机?如果没有指定factory-method, 会返回StaticFactoryBean的实?卌回工厂Bean的实?br/>}
2.实例工厂
创徏具体Bean实例的是实例,不是静态方?/div>
import java.text.SimpleDateFormat; import java.util.Date;
public class InstanceFactoryBean {
private String format = "yy-MM-dd HH:mm:ss";
public void setFormat(String format) { this.format = format; }
public String createTime() { return new SimpleDateFormat(format).format(new Date()); } }
配置文g需要配|两个bean:W一个Bean和普通的Bean没有区别,W二个bean定义如何通过工厂Bean获取Bean,需要指?strong>工厂Bean的名U和Ҏ名称
<bean id="instanceFactoryBean" class="example.chapter3.InstanceFactoryBean"> <property name="format" value="yyyy-MM-dd HH:mm:ss" /> </bean>
<bean id="currentTime"factory-bean ="instanceFactoryBean"factory-method ="createTime" />
试:
public static void main(String[] args) { XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("config.xml")); System.out.println(factory.getBean("currentTime")); }
3.实现FactoryBean接口
public class PiFactoryBean implements FactoryBean {
public Object getObject() throws Exception { return new Double(3.14159265358979); }
public Class getObjectType() { return Double.class; }
public boolean isSingleton() { return true; }
}
实现了FactoryBean接口的Bean,不再被视为普通的Bean.Spring会自动检?
<bean id="pi" class="example.chapter3.PiFactoryBean" />
试
public static void main(String[] args) throws Exception { XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("config.xml")); System.out.println(factory.getBean("pi"));//q回PiFactoryBean 的工厂方法getObjectq回的Double对象实例 //PiFactoryBean p = (PiFactoryBean)factory.getBean("&pi"); //?&"q回工厂Bean的实? //System.out.println(p.getObject()); }
]]>
Spring2.0--W记2 http://www.aygfsteel.com/tianya0801/archive/2008/02/25/181995.html未知数据 未知数据 Mon, 25 Feb 2008 06:33:00 GMT http://www.aygfsteel.com/tianya0801/archive/2008/02/25/181995.html http://www.aygfsteel.com/tianya0801/comments/181995.html http://www.aygfsteel.com/tianya0801/archive/2008/02/25/181995.html#Feedback 0 http://www.aygfsteel.com/tianya0801/comments/commentRss/181995.html http://www.aygfsteel.com/tianya0801/services/trackbacks/181995.html W三?Ioc容器
3.2.1 容器的概?/strong>
Spring容器提供的功能主要包?/span>
1.lg的生命周期管?/span>
2.lg的配|和l装服务
3.AOP支持
4.建立在AOP之上的声明式事物服务
3.2.2 IoC的概?/strong>
IoC inversion of Control 控制反{
public class BookService {
private BookDao bookDao = new DbBookDao();
public List<Book> listBooksByAuthor(String author) {
List<Book> books = bookDao.listAll();
Iterator<Book> it = books.iterator();
while(it.hasNext()) {
if(!it.next().getAuthor().equals(author)) {
it.remove();
}
}
return books;
}
}
如果pȝ中有很多lg,其生命周期和怺之间的依赖关pd果由lg自己来维?不但大大增加了系l的复杂E度,而且Dlglg很紧的耦合,l而给试和维护带来很大困?
在Ioc模式?控制权发生了反{.lg不再由应用程序来创徏和配|?而是由Ioc容器来负?应用E序只是直接使用已经创徏和配|好的组?
public class BookService {
private BookDao bookDao;
public void setBookDao(BookDao bookDao){
this.bookDao=bookDao;
}
public List<Book> listBooksByAuthor(String author) {
List<Book> books = bookDao.listAll();
Iterator<Book> it = books.iterator();
while(it.hasNext()) {
if(!it.next().getAuthor().equals(author)) {
it.remove();
}
}
return books;
上面没有创徏lgbookDao的代?只有使用lg.从而实Clg的配|和使用的分?q由Ioc容器负责理lg的生命周?
3.2.3 依赖注入的方?/strong>
Z让组件能在IoC容器中被装配出来,需要某U注入机?Ioc使用"注入"机制一U组件注入到另一U组件中.
Type1:接口注入
Type2:讄属性注?/div>
Type3:构造方法注?/div>
3.3 Spring提供的IoC容器
1.高扩展?strong>无R入式的框?/div>
2.支持两种依赖注入方式:讄属性注入和构造方法注?
3.提供两种不同的容?BeanFactory和ApplicationContext
3.3.1 BeanFactory
应用E序Bean的创建和配置全部委托lBeanFactory,然后从BeanFactory获取Beanq用Bean.程如下:
启动应用E序-->实例化BeanFactory -->从BeanFactory中获取Bean-->使用Bean-->销毁BeanFactory-->应用E序l束
FileInputStream ("beans.xml");
XmlBeanFactory factory = newXmlBeanFactory (is);
init-method="init"> <property name="size" value="10" /> <property name="version" value="1.0" />
ref="basicBean" />
</bean>
public class ListBean {
public void setChildren(List children){}//普通list public void setPrices(List<Float> prices) {}//泛型list public void setFi(int[] fi) {}//int数组 }
<bean id="listBean" class="example.chapter3.ListBean"> <property name="children"> <list> <value>A String</value><ref bean="basicBean" /> </list> </property> <property name="prices"> <list> <value>1.24</value> <value>2.24</value> <value>3.24</value> </list> </property> <property name="fi"> <list> <value>1</value> <value>2</value> <value>3</value> <value>4</value> <value>5</value> </list> </property> </bean>
1.讄list和数l的Ҏ是在<list>?lt;/list>之间包含若干<value>?lt;ref>节点,可以混合使用<value>?lt;ref>
2.使用java5的泛?Spring2.0可以强制?lt;value>的D{化ؓFloatcd
3.setcd的注入和普通list相同,但set中不包含重复元素.
4.map的注?每一w是由一个键值和对应的值组?例如:
public class MapBean {
public void setWeekday(Map map) {} }
<bean id="mapBean" class="example.chapter3.MapBean"> <property name="weekday"> <map> <entry key="Monday"> <value>one</value> </entry> <entry key="Tuesday"> <ref bean="listBean" /> </entry> </map> </property> </bean> key也可以是L的Object. <bean id="mapBean" class="example.chapter3.MapBean"> <property name="weekday"> <map> <entry> <key><ref bean="basicBean"></key> <value>basic</value> </entry> <entry> <key><ref bean="basicBean"></key> <ref bean="setBean" /> </entry> <!-- 可简写成 <entry key-ref="basicBean" value="basic" /> <entry key-ref="listBean" value-ref="setBean" /> --> </map> </property> </bean>
} public ConstructorBean(String min,String max) { System.out.println("(String,String)"); } }
<constructor-arg type ="int" value ="100"> <constructor-arg type="int" value="200"> </bean>
如果不指定scope,默认gؓsingleton.Spring的IoC容器仅ؓ每个bean创徏一个实?q保持Bean的引?也就是说每次调用getBean()Ҏh某一bean ?Spring总返回相同的Bean实例
2.prototype
每次都返回一个新创徏的bean实例.因此,Spring容器一旦将实例交给客户?׃再对其跟t引?所以不能对prototype作用域的Bean定义destroy-method.
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("config.xml"); System.out.println("Get date: "+context.getBean("date")); Thread.sleep(1000); System.out.println("Get date: "+context.getBean("date")); Thread.sleep(1000); System.out.println("Get date: "+context.getBean("date")); Thread.sleep(1000); }
<bean id="date" class="java.util.Date" scope="prototype" />
打印出的旉是不同的,说明q回3个不同的date对象实例,如果Lscope,则每ơ打印出的时间都是一L.
]]>Spring2.0--W记1 http://www.aygfsteel.com/tianya0801/archive/2008/02/25/181870.html未知数据 未知数据 Mon, 25 Feb 2008 00:35:00 GMT http://www.aygfsteel.com/tianya0801/archive/2008/02/25/181870.html http://www.aygfsteel.com/tianya0801/comments/181870.html http://www.aygfsteel.com/tianya0801/archive/2008/02/25/181870.html#Feedback 0 http://www.aygfsteel.com/tianya0801/comments/commentRss/181870.html http://www.aygfsteel.com/tianya0801/services/trackbacks/181870.html
W一?
1.1 spring介绍
Rod Johnson提出,抛弃了EJB的重量lg,使用javaBean作ؓlg实现,轻量U框?
spring是一个实CAOP功能的Ioc容器.不同于IQ,不需要全功能的javaEE服务?它可以在仅支持web容器的javaEE服务器上,或者直接在普通的main()中启?
W二?
1.1 resin安装
resin3.1安装报错:Can't find java executable in d:\jdk1.5
Couldn't start "(null)" -classpath
原因:
java_home没找?重新讄,需要删掉原来的java_home,再新?q且只能有一个目?/div>
1.2 HelloWorld
在src下添加builds.xml配置
]]>
վ֩ģ壺
ר |
ʷ |
|
|
|
|
ƽ |
|
|
|
|
Ͱ |
̷ |
|
|
|
|
|
|
ɽ |
|
Ƽ |
|
|
|
|
|
Ϫ |
|
|
³ľ |
|
|
|
|
Ͳ |
˿ |
÷ӿ |
|
|
Ž |