附录

XML 模式

本部分附录列出了与集成技术相关的 XML 模式。

jee 模式

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

要使用 jee 模式中的元素,您需要在 Infra 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="infra.jndi.JndiObjectFactoryBean">
  <property name="jndiName" value="jdbc/MyDataSource"/>
</bean>
<bean id="userDao" class="com.foo.JdbcUserDao">
  <!-- Infra 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">
  <!-- Infra will do the cast automatically (as usual) -->
  <property name="dataSource" ref="dataSource"/>
</bean>

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

以下示例展示了如何在不使用 jee 的情况下使用 JNDI 查找环境变量:

<bean id="simple" class="infra.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="infra.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">
  <!-- 换行分隔的环境键值对(标准 Properties 格式) -->
  <jee:environment>
    sing=song
    ping=pong
  </jee:environment>
</jee:jndi-lookup>

<jee:jndi-lookup/> (复杂)

以下示例展示了如何在不使用 jee 的情况下使用 JNDI 查找数据源和许多不同的属性:

<bean id="simple" class="infra.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"/>