備查:放上書上所寫的Bean配置及調用方式:


xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<description>Spring Bean Configuration Sample</description>
<bean
id="TheAction" ⑴
class="net.xiaxin.spring.qs.UpperAction" ⑵
singleton="true" ⑶
init-method="init" ⑷
destroy-method="cleanup" ⑸
depends-on="ActionManager" ⑹
>
<property name="message">
<value>HeLLo</value> ⑺
</property>
<property name="desc">
<null/>
</property>
<property name="dataSource">
<ref local="dataSource"/> ⑻
</property>
</bean>
<bean
id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean"
>
<property name="jndiName">
<value>java:comp/env/jdbc/sample</value>
</property>
</bean>
</beans> 里面需要留意的就是空值及引用的寫法,測試中好象不加入那條DTD的定義,總報不合法的XML定義錯誤。
--使用:


InputStream is = new FileInputStream("beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(is);
Action action = (Action) factory.getBean("TheAction");或


ApplicationContext ac = new FileSystemXmlApplicationContext("beans.xml");
Action action = (Action)ac.getBean("TheAction");
再有里面提到有“熱布署”的名詞,應該就等同于:



public class MyProperties
{
private String fileName = null;
private File propFile = null;
private long lastModified ;

public MyProperties(String fileName)
{
this.fileName = fileName;
}

private void loadPropFile()
{
this.propFile = new File(this.fileName);
}

private boolean isChanged()
{
boolean changed = false;

if(this.propFile.lastModified() != this.lastModified)
{
changed = true;
}
return changed;
}

public Object getProp(String propName)
{

if(isChanged())
{
this.loadPropFile();
}
.;
}
}
事件傳播機制:
基于觀察者模式的實現。
由ApplicationContext負責通知全部實現了ApplicationListener接口的Bean,應該是不能實現分類通知的。
在例子中使用了instanceof這類的類型判斷,將Listener與Event牢牢掛住了,感覺不是很爽。
我的想法是:只在ApplictionContext中定義一個ApplictionListener,讓它充當分發器和缺省Event處理器的角色;在ActionEvent之上再封一個接口ActionEventEx,擴展一個接口getEvnetType,讓全部的ActionEvent實例都實現自ActionEventEx接口。并在ApplictionListener中實現一個BeanFactory,根據ActionEvent的實例,強轉至ActionEventEx,取得eventType,再從ApplictionContext中取得對應的Bean來處理事件。

































--使用:









再有里面提到有“熱布署”的名詞,應該就等同于:











































事件傳播機制:
基于觀察者模式的實現。
由ApplicationContext負責通知全部實現了ApplicationListener接口的Bean,應該是不能實現分類通知的。
在例子中使用了instanceof這類的類型判斷,將Listener與Event牢牢掛住了,感覺不是很爽。
我的想法是:只在ApplictionContext中定義一個ApplictionListener,讓它充當分發器和缺省Event處理器的角色;在ActionEvent之上再封一個接口ActionEventEx,擴展一個接口getEvnetType,讓全部的ActionEvent實例都實現自ActionEventEx接口。并在ApplictionListener中實現一個BeanFactory,根據ActionEvent的實例,強轉至ActionEventEx,取得eventType,再從ApplictionContext中取得對應的Bean來處理事件。