|
对于最新稳定版本,请使用 Spring Framework 7.0.6! |
附录
XML Schema
本附录的这一部分列出了与集成技术相关的 XML Schema。
这jee架构
jee 元素用于处理与 Jakarta EE(企业版)配置相关的问题,
例如查找 JNDI 对象和定义 EJB 引用。
要使用 jee 命名空间中的元素,您需要在 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 命名空间的情况下,通过 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>
以下示例展示了如何使用 JNDI 通过 jee 命名空间查找数据源:
<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>
以下示例展示了如何使用 JNDI 通过 jee 查找环境变量:
<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>
以下示例展示了如何使用 JNDI 通过 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/>(复杂)
以下示例展示了如何使用 JNDI 查找数据源以及多个不同的属性,而不使用 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>
以下示例展示了如何使用 JNDI 查找数据源以及通过 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/>(简单)
<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/> 元素用于配置对一个 remote 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 的
消息监听器容器(Message Listener Containers)。这些元素在
JMS 章节中题为 JMS 命名空间支持(JMS Namespace Support) 的部分有详细说明。
有关此支持功能及 jms 元素本身的完整详情,请参阅该章节。
为了保证完整性,若要在您的 Spring XML 配置文件中使用 jms 命名空间中的元素,您需要在配置文件顶部包含以下前导声明。以下代码片段中的文本引用了正确的 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架构
您可以使用 cache 元素来启用对 Spring 的 @CacheEvict、@CachePut 和 @Caching 注解的支持。它还支持基于 XML 的声明式缓存。详情请参见
启用缓存注解 和
基于 XML 的声明式缓存。
要使用 cache 命名空间中的元素,您需要在 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>