此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Framework 6.1.10Spring中文文档

此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Framework 6.1.10Spring中文文档

XML 架构

附录的这一部分列出了与集成技术相关的 XML 模式。Spring中文文档

架构jee

这些元素处理与 Jakarta EE (Enterprise Edition) 配置相关的问题, 例如查找 JNDI 对象并定义 EJB 引用。jeeSpring中文文档

若要使用架构中的元素,需要在顶部包含以下前导码 的 Spring XML 配置文件。以下代码片段中的文本引用了 正确的架构,以便命名空间中的元素可供您使用:jeejeeSpring中文文档

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

以下示例显示了如何使用 JNDI 查找没有模式的数据源:jeeSpring中文文档

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

以下示例显示了如何使用 JNDI 查找具有模式的数据源:jeeSpring中文文档

<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 环境设置)

以下示例显示了如何使用 JNDI 查找环境变量,而无需:jeeSpring中文文档

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

以下示例显示了如何使用 JNDI 查找环境变量:jeeSpring中文文档

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

<jee:jndi-lookup/>(具有多个 JNDI 环境设置)

以下示例说明如何使用 JNDI 查找多个环境变量 没有:jeeSpring中文文档

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

以下示例显示了如何使用 JNDI 查找具有以下命令的多个环境变量:jeeSpring中文文档

<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/>(复杂)

以下示例显示了如何使用 JNDI 查找数据源和许多 不同的属性没有:jeeSpring中文文档

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

以下示例显示了如何使用 JNDI 查找数据源和许多 不同的属性:jeeSpring中文文档

<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/>(简单)

该元素配置对本地 EJB 无状态会话 Bean 的引用。<jee:local-slsb/>Spring中文文档

以下示例说明如何配置对本地 EJB 无状态会话 Bean 的引用 没有:jeeSpring中文文档

<bean id="simple"
		class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
	<property name="jndiName" value="ejb/RentalServiceBean"/>
	<property name="businessInterface" value="com.foo.service.RentalService"/>
</bean>

以下示例说明如何配置对本地 EJB 无状态会话 Bean 的引用 跟:jeeSpring中文文档

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

<jee:local-slsb/>(复杂)

该元素配置对本地 EJB 无状态会话 Bean 的引用。<jee:local-slsb/>Spring中文文档

以下示例说明如何配置对本地 EJB 无状态会话 Bean 的引用 和一些没有以下属性的属性:jeeSpring中文文档

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

以下示例说明如何配置对本地 EJB 无状态会话 Bean 的引用 以及许多具有以下属性的属性:jeeSpring中文文档

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

该元素配置对 EJB 无状态会话 Bean 的引用。<jee:remote-slsb/>remoteSpring中文文档

以下示例显示如何配置对远程 EJB 无状态会话 Bean 的引用 没有:jeeSpring中文文档

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

以下示例显示如何配置对远程 EJB 无状态会话 Bean 的引用 跟:jeeSpring中文文档

<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 相关的 bean,例如 Spring 的消息侦听器容器。这些元素在 标题为 JMS 命名空间支持JMS 章节。有关此支持的完整详细信息,请参阅该章 以及元素本身。jmsjmsSpring中文文档

为了完整起见,要使用架构中的元素,您需要 Spring XML 配置文件顶部的以下前导码。文本 以下代码片段引用了正确的架构,以便命名空间中的元素 可供您使用:jmsjmsSpring中文文档

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

架构cache

您可以使用这些元素来启用对 Spring 的 、 、 和注释。它还支持基于 XML 的声明性缓存。有关详细信息,请参阅启用缓存批注基于 XML 的声明性缓存cache@CacheEvict@CachePut@CachingSpring中文文档

若要使用架构中的元素,需要在 Spring XML 配置文件的顶部。以下代码段中的文本引用 正确的架构,以便命名空间中的元素可供您使用:cachecacheSpring中文文档

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