Appendix

  • jee:用于处理与 Jakarta EE 相关的配置,如 JNDI 查找和 EJB 引用。

  • jms:用于配置与 JMS 相关的 Bean,如 Message Listener 容器。

  • cache:用于启用对 Spring 缓存注解和声明式缓存的支持。

该文档还指导用户如何在 Spring XML 配置文件中使用这些模式。

XML Schemas

本附录的这一节列出了与集成技术相关的 XML 模式。

This part of the appendix lists XML schemas related to integration technologies.

The jee Schema

jee 元素处理与 Jakarta EE(企业版)配置相关的问题,如查找 JNDI 对象和定义 EJB 引用。

The jee elements deal with issues related to Jakarta EE (Enterprise Edition) configuration, such as looking up a JNDI object and defining EJB references.

要使用 jee 模式中的元素,您需要在 Spring XML 配置文件的顶部有以下前导。以下代码片段中的文本引用了正确的模式,以便您可以使用 jee 命名空间中的元素:

To use the elements in the jee schema, you need to have the following preamble at the top of your Spring XML configuration file. The text in the following snippet references the correct schema so that the elements in the jee namespace are available to you:

<?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/> (simple)

以下示例演示如何在不使用 jee 模式的情况下通过 JNDI 查找数据源:

The following example shows how to use JNDI to look up a data source without the jee schema:

<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 查找数据源:

The following example shows how to use JNDI to look up a data source with the jee schema:

<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/> (with Single JNDI Environment Setting)

以下示例演示如何在没有 jee 的情况下通过 JNDI 查找环境变量:

The following example shows how to use JNDI to look up an environment variable without jee:

<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 查找环境变量:

The following example shows how to use JNDI to look up an environment variable with jee:

<jee:jndi-lookup id="simple" jndi-name="jdbc/MyDataSource">
	<jee:environment>ping=pong</jee:environment>
</jee:jndi-lookup>

<jee:jndi-lookup/> (with Multiple JNDI Environment Settings)

以下示例演示如何在没有 jee 的情况下通过 JNDI 查找多个环境变量:

The following example shows how to use JNDI to look up multiple environment variables without jee:

<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 查找多个环境变量:

The following example shows how to use JNDI to look up multiple environment variables with jee:

<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/> (Complex)

以下示例演示如何在不使用 jee 的情况下通过 JNDI 查找数据源和若干不同属性:

The following example shows how to use JNDI to look up a data source and a number of different properties without jee:

<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 查找数据源和若干不同属性:

The following example shows how to use JNDI to look up a data source and a number of different properties with jee:

<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/> (Simple)

<jee:local-slsb/> 元素配置对一个本地 EJB 无状态会话 Bean 的引用。

The <jee:local-slsb/> element configures a reference to a local EJB Stateless Session Bean.

以下示例演示如何在不使用 jee 的情况下配置对本地 EJB 无状态会话 Bean 的引用:

The following example shows how to configures a reference to a local EJB Stateless Session Bean without jee:

<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 的引用:

The following example shows how to configures a reference to a local EJB Stateless Session Bean with jee:

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

<jee:local-slsb/> (Complex)

<jee:local-slsb/> 元素配置对一个本地 EJB 无状态会话 Bean 的引用。

The <jee:local-slsb/> element configures a reference to a local EJB Stateless Session Bean.

以下示例演示如何在不使用 jee 的情况下配置对本地 EJB 无状态会话 Bean 及若干属性的引用:

The following example shows how to configures a reference to a local EJB Stateless Session Bean and a number of properties without jee:

<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 及若干属性的引用:

The following example shows how to configures a reference to a local EJB Stateless Session Bean and a number of properties with jee:

<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 的引用。

The <jee:remote-slsb/> element configures a reference to a remote EJB Stateless Session Bean.

以下示例演示如何在不使用 jee 的情况下配置对远程 EJB 无状态会话 Bean 的引用:

The following example shows how to configures a reference to a remote EJB Stateless Session Bean without jee:

<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 的引用:

The following example shows how to configures a reference to a remote EJB Stateless Session Bean with jee:

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

The jms Schema

jms 元素用于配置与 JMS 相关的 bean,例如 Spring 的 Message Listener Containers。这些元素在 JMS chapterJMS Namespace Support 部分中有详细说明。有关此支持和 jms 元素本身的完整详细信息,请参见该章节。

The jms elements deal with configuring JMS-related beans, such as Spring’s Message Listener Containers. These elements are detailed in the section of the JMS chapter entitled JMS Namespace Support . See that chapter for full details on this support and the jms elements themselves.

为了完整起见,要使用“jms”架构中的元素,您需要在 Spring XML 配置文件的顶部包含以下前导信息。以下代码片段中的文本引用正确的架构,以便“jms”命名空间中的元素对您可用:

In the interest of completeness, to use the elements in the jms schema, you need to have the following preamble at the top of your Spring XML configuration file. The text in the following snippet references the correct schema so that the elements in the jms namespace are available to you:

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

Using <context:mbean-export/>

此元素在 Configuring Annotation-based MBean Export 中有详细说明。

This element is detailed in Configuring Annotation-based MBean Export.

The cache Schema

你可以通过 cache 元素来支持 Spring 的 @CacheEvict, @CachePut`和 `@Caching 注解。它还支持基于 XML 的声明式缓存。有关详细信息,请参阅 Enabling Caching AnnotationsDeclarative XML-based Caching

You can use the cache elements to enable support for Spring’s @CacheEvict, @CachePut, and @Caching annotations. It it also supports declarative XML-based caching. See Enabling Caching Annotations and Declarative XML-based Caching for details.

要使用“cache”架构中的元素,您需要在 Spring XML 配置文件的顶部包含以下前导信息。以下代码片段中的文本引用正确的架构,以便“cache”命名空间中的元素对您可用:

To use the elements in the cache schema, you need to have the following preamble at the top of your Spring XML configuration file. The text in the following snippet references the correct schema so that the elements in the cache namespace are available to you:

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