附錄

XML Schema

附錄的這部分列出了與整合技術相關的 XML Schema。

jee Schema

jee 元素處理與 Jakarta EE (企業版) 配置相關的問題,例如查找 JNDI 物件和定義 EJB 參考。

若要使用 jee schema 中的元素,您需要在 Spring XML 配置檔案的頂部包含以下前言。以下程式碼片段中的文字參考了正確的 schema,以便 jee namespace 中的元素可供您使用

<?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 Stateless Session Bean 的參考。

以下範例示範如何在不使用 jee 的情況下,配置對本機 EJB Stateless 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 Stateless Session Bean 的參考

<jee:local-slsb id="simpleSlsb" jndi-name="ejb/RentalServiceBean"
		business-interface="com.foo.service.RentalService"/>

<jee:local-slsb/> (複雜)

<jee:local-slsb/> 元素配置對本機 EJB Stateless Session Bean 的參考。

以下範例示範如何在不使用 jee 的情況下,配置對本機 EJB Stateless 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 Stateless 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 Stateless Session Bean 的參考。

以下範例示範如何在不使用 jee 的情況下,配置對遠端 EJB Stateless 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 Stateless 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 Namespace 支援 的章節中詳細說明。請參閱該章節以取得有關此支援和 jms 元素本身的完整詳細資訊。

為了完整起見,若要使用 jms schema 中的元素,您需要在 Spring XML 配置檔案的頂部包含以下前言。以下程式碼片段中的文字參考了正確的 schema,以便 jms namespace 中的元素可供您使用

<?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 namespace 中的元素可供您使用

<?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>