简体   繁体   中英

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

I am pretty new in Spring and I have a little doubt related the concept of namespace into my XML configuration files.

So for example into the root-context.xml file of a project on which I am working on there is this definition:

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

that have the jee namepace that is also specified into the beans external container by:

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

Now my doubt is, what exactly is this definition having id="datasource"? This one:

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

Is it a classic bean of Spring having a specific namespace because it belong to a specific domain of bean (having a specific pourpose) or what?

As Explained in the spring doc:

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

Here after an example from spring doc:

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

Using jee jndi-lookup

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

More details here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM