附錄
XML Schema
附錄的這部分列出了與整合技術相關的 XML Schema。
jee
Schema
jee
元素處理與 Jakarta EE (企業版) 配置相關的問題,例如查詢 JNDI 物件和定義 EJB 引用。
要使用 jee
Schema 中的元素,您需要在 Spring XML 配置檔案頂部新增以下序言。以下程式碼片段中的文字引用了正確的 Schema,以便 jee
名稱空間中的元素對您可用。
<?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:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee
https://www.springframework.org/schema/jee/spring-jee.xsd">
<!-- bean definitions here -->
</beans>
<jee:jndi-lookup/> (簡單)
以下示例展示瞭如何在沒有 jee
Schema 的情況下使用 JNDI 查詢資料來源
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/MyDataSource"/>
</bean>
<bean id="userDao" class="com.foo.JdbcUserDao">
<!-- Spring will do the cast automatically (as usual) -->
<property name="dataSource" ref="dataSource"/>
</bean>
以下示例展示瞭如何在有 jee
Schema 的情況下使用 JNDI 查詢資料來源
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/MyDataSource"/>
<bean id="userDao" class="com.foo.JdbcUserDao">
<!-- Spring will do the cast automatically (as usual) -->
<property name="dataSource" ref="dataSource"/>
</bean>
<jee:jndi-lookup/>
(帶單個 JNDI 環境設定)
以下示例展示瞭如何在沒有 jee
的情況下使用 JNDI 查詢環境變數
<bean id="simple" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/MyDataSource"/>
<property name="jndiEnvironment">
<props>
<prop key="ping">pong</prop>
</props>
</property>
</bean>
以下示例展示瞭如何在有 jee
的情況下使用 JNDI 查詢環境變數
<jee:jndi-lookup id="simple" jndi-name="jdbc/MyDataSource">
<jee:environment>ping=pong</jee:environment>
</jee:jndi-lookup>
<jee:jndi-lookup/>
(帶多個 JNDI 環境設定)
以下示例展示瞭如何在沒有 jee
的情況下使用 JNDI 查詢多個環境變數
<bean id="simple" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/MyDataSource"/>
<property name="jndiEnvironment">
<props>
<prop key="sing">song</prop>
<prop key="ping">pong</prop>
</props>
</property>
</bean>
以下示例展示瞭如何在有 jee
的情況下使用 JNDI 查詢多個環境變數
<jee:jndi-lookup id="simple" jndi-name="jdbc/MyDataSource">
<!-- newline-separated, key-value pairs for the environment (standard Properties format) -->
<jee:environment>
sing=song
ping=pong
</jee:environment>
</jee:jndi-lookup>
<jee:jndi-lookup/>
(複雜)
以下示例展示瞭如何在沒有 jee
的情況下使用 JNDI 查詢資料來源和多個不同屬性
<bean id="simple" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/MyDataSource"/>
<property name="cache" value="true"/>
<property name="resourceRef" value="true"/>
<property name="lookupOnStartup" value="false"/>
<property name="expectedType" value="com.myapp.DefaultThing"/>
<property name="proxyInterface" value="com.myapp.Thing"/>
</bean>
以下示例展示瞭如何在有 jee
的情況下使用 JNDI 查詢資料來源和多個不同屬性
<jee:jndi-lookup id="simple"
jndi-name="jdbc/MyDataSource"
cache="true"
resource-ref="true"
lookup-on-startup="false"
expected-type="com.myapp.DefaultThing"
proxy-interface="com.myapp.Thing"/>
<jee:local-slsb/>
(簡單)
<jee:local-slsb/>
元素配置對本地 EJB 無狀態 Session Bean 的引用。
以下示例展示瞭如何在沒有 jee
的情況下配置對本地 EJB 無狀態 Session Bean 的引用
<bean id="simple"
class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
<property name="jndiName" value="ejb/RentalServiceBean"/>
<property name="businessInterface" value="com.foo.service.RentalService"/>
</bean>
以下示例展示瞭如何在有 jee
的情況下配置對本地 EJB 無狀態 Session Bean 的引用
<jee:local-slsb id="simpleSlsb" jndi-name="ejb/RentalServiceBean"
business-interface="com.foo.service.RentalService"/>
<jee:local-slsb/>
(複雜)
<jee:local-slsb/>
元素配置對本地 EJB 無狀態 Session Bean 的引用。
以下示例展示瞭如何在沒有 jee
的情況下配置對本地 EJB 無狀態 Session Bean 的引用和多個屬性
<bean id="complexLocalEjb"
class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
<property name="jndiName" value="ejb/RentalServiceBean"/>
<property name="businessInterface" value="com.example.service.RentalService"/>
<property name="cacheHome" value="true"/>
<property name="lookupHomeOnStartup" value="true"/>
<property name="resourceRef" value="true"/>
</bean>
以下示例展示瞭如何在有 jee
的情況下配置對本地 EJB 無狀態 Session Bean 的引用和多個屬性
<jee:local-slsb id="complexLocalEjb"
jndi-name="ejb/RentalServiceBean"
business-interface="com.foo.service.RentalService"
cache-home="true"
lookup-home-on-startup="true"
resource-ref="true">
<jee:remote-slsb/>
<jee:remote-slsb/>
元素配置對 remote
EJB 無狀態 Session Bean 的引用。
以下示例展示瞭如何在沒有 jee
的情況下配置對遠端 EJB 無狀態 Session Bean 的引用
<bean id="complexRemoteEjb"
class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
<property name="jndiName" value="ejb/MyRemoteBean"/>
<property name="businessInterface" value="com.foo.service.RentalService"/>
<property name="cacheHome" value="true"/>
<property name="lookupHomeOnStartup" value="true"/>
<property name="resourceRef" value="true"/>
<property name="homeInterface" value="com.foo.service.RentalService"/>
<property name="refreshHomeOnConnectFailure" value="true"/>
</bean>
以下示例展示瞭如何在有 jee
的情況下配置對遠端 EJB 無狀態 Session Bean 的引用
<jee:remote-slsb id="complexRemoteEjb"
jndi-name="ejb/MyRemoteBean"
business-interface="com.foo.service.RentalService"
cache-home="true"
lookup-home-on-startup="true"
resource-ref="true"
home-interface="com.foo.service.RentalService"
refresh-home-on-connect-failure="true">
jms
Schema
jms
元素處理與 JMS 相關的 Bean 配置,例如 Spring 的 訊息監聽器容器。這些元素在JMS 章的JMS 名稱空間支援部分有詳細介紹。請參閱該章以獲取有關此支援和 jms
元素本身的完整詳細資訊。
為了完整起見,要使用 jms
Schema 中的元素,您需要在 Spring XML 配置檔案頂部新增以下序言。以下程式碼片段中的文字引用了正確的 Schema,以便 jms
名稱空間中的元素對您可用。
<?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:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jms
https://www.springframework.org/schema/jms/spring-jms.xsd">
<!-- bean definitions here -->
</beans>
使用 <context:mbean-export/>
此元素在配置基於註解的 MBean 匯出中有詳細介紹。
cache
Schema
您可以使用 cache
元素啟用對 Spring 的 @CacheEvict
、@CachePut
和 @Caching
註解的支援。它還支援基於 XML 的宣告式快取。有關詳細資訊,請參閱啟用快取註解和基於 XML 的宣告式快取。
要使用 cache
Schema 中的元素,您需要在 Spring XML 配置檔案頂部新增以下序言。以下程式碼片段中的文字引用了正確的 Schema,以便 cache
名稱空間中的元素對您可用。
<?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:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache
https://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- bean definitions here -->
</beans>