?
? ????? PHP ??? ???? ??? ?? ??
最后這一章提供了一些和動態(tài)語言有關(guān)的小知識點。
使用Spring AOP框架對腳本化bean進行通知已經(jīng)成為可能。Spring AOP框架實際上不關(guān)心需要被 通知的bean是否是腳本化bean,因此你所使用的全部AOP用例和功能對腳本化bean都有效。 唯一需要注意的是,通知腳本化bean的時候,你不能使用基于類的代理, 而只能使用基于接口的代理。
當然不用局限于在通知腳本化bean方面,你也可以使用支持的動態(tài)語言實現(xiàn)切面, 并使用該切面通知其他的Spring bean。這樣才是真正的利用了動態(tài)語言支持的優(yōu)勢。
在不是馬上起效的情況中,腳本化bean當然也能和其他bean一樣定義作用域。
<lang:language/>
元素的scope
屬性可以幫助你控制底層的腳本化bean的作用域,
這樣這些腳本化bean就和普通的bean沒有區(qū)別了。(scope的默認值任然是singleton,
和普通bean沒有區(qū)別。)
下面的示例使用scope
屬性將Groovy bean定義為prototype。
<?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:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd">
<lang:groovy id="messenger" script-source="classpath:Messenger.groovy" scope="prototype">
<lang:property name="message" value="I Can Do The RoboCop" />
</lang:groovy>
<bean id="bookingService" class="x.y.DefaultBookingService">
<property name="messenger" ref="messenger" />
</bean>
</beans>
第?3?章 IoC(控制反轉(zhuǎn))容器 中的第?3.4?節(jié) “Bean的作用域”章節(jié)詳細討論了Spring框架支持的作用域。