附錄

XML 模式

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

jee 模式

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

要使用 jee 模式中的元素,您需要在 Spring XML 配置檔案頂部新增以下序言。以下片段中的文字引用了正確的模式,以便 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 模式的情況下使用 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 模式的情況下使用 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 無狀態會話 Bean 的引用。

以下示例展示瞭如何在沒有 jee 的情況下配置對本地 EJB 無狀態會話 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 無狀態會話 Bean 的引用。

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

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

<jee:local-slsb/> 元素配置對本地 EJB 無狀態會話 Bean 的引用。

以下示例展示瞭如何在沒有 jee 的情況下配置對本地 EJB 無狀態會話 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 無狀態會話 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/> 元素配置對 遠端 EJB 無狀態會話 Bean 的引用。

以下示例展示瞭如何在沒有 jee 的情況下配置對遠端 EJB 無狀態會話 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 無狀態會話 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 模式

jms 元素處理 JMS 相關 bean 的配置,例如 Spring 的 訊息監聽器容器。這些元素在 JMS 章 中名為 JMS 名稱空間支援 的部分進行了詳細說明。有關此支援和 jms 元素本身的完整詳細資訊,請參閱該章。

為求完整性,要使用 jms 模式中的元素,您需要在 Spring XML 配置檔案頂部新增以下序言。以下片段中的文字引用了正確的模式,以便 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 模式

您可以使用 cache 元素來啟用對 Spring 的 @CacheEvict@CachePut@Caching 註解的支援。它還支援宣告式基於 XML 的快取。有關詳細資訊,請參閱 啟用快取註解宣告式基於 XML 的快取

要使用 cache 模式中的元素,您需要在 Spring XML 配置檔案頂部新增以下序言。以下片段中的文字引用了正確的模式,以便 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>
© . This site is unofficial and not affiliated with VMware.