关于Spring namespace 到XML 配置文件的一些疑问。具体如何运作?

Some doubts about Spring namespace into XML configuration file. How exactly works?

我是 Spring 的新手,我有点怀疑将命名空间的概念与我的 XML 配置文件相关联。

例如,在我正在处理的项目的 root-context.xml 文件中有这样的定义:

<jee:jndi-lookup jndi-name="java:jboss/datasources/myDbDS" id="datasource" expected-type="javax.sql.DataSource" />

具有 jee 名称空间,该名称空间也由以下人员指定到 beans 外部容器中:

xmlns:jee="http://www.springframework.org/schema/jee"

现在我的疑问是,这个id="datasource"的定义到底是什么?这个:

<jee:jndi-lookup jndi-name="java:jboss/datasources/myDbDS" id="datasource" expected-type="javax.sql.DataSource" />

它是 Spring 的经典 bean 具有特定命名空间,因为它属于 bean 的特定域(具有特定用途)还是什么?

如 spring 文档中所述:

The jee tags deal with Java EE (Java Enterprise Edition)-related configuration issues, such as looking up a JNDI object and defining EJB references

这里是 spring 文档中的示例:

不使用 jee jndi-lookup

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

更多详情here