This rule flags the
property
element named
jndiName
that belongs to a Spring bean with class:
org.springframework.jndi.JndiObjectFactoryBean
.
This element is being flagged in order to ensure that corresponding elements in the
web.xml and the
WebSphere traditional and Liberty bindings files are properly configured.
This rule flags the property under the following conditions:
- The Spring configuration file is in a web project, and within that file, the property
jndiName
is configured in a bean entry, and either
- the value of the
jndiName
property does not contain a variable.
That is, the value does not contain a
$
or
{
. Or
- the value of the
jndiName
property does not start with "java:comp/env/"
- and the property
proxyInterface
within the same bean is configured, and
- the value of the
proxyInterface
property is
javax.sql.DataSource
and
- either the web.xml file does not exist, or
- the web.xml file does not contain a resource reference with a value corresponding to the value of the
jndiName
property.
An automated fix will create a resource reference in the web.xml
file if the resource reference does not already exist. It will also create
the appropriate entry in the IBM bindings file. For example, consider
the following fragment from a Spring configuration file:
<bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/springdb"/>
<property name="lookupOnStartup" value="false"/>
<property name="cache" value="true"/>
<property name="proxyInterface" value="javax.sql.DataSource"/>
</bean>
This file contains a
jndiName
property and
proxyInterface
property set to javax.sql.DataSource.
The automated fix will create a resource reference if it is missing
from the
web.xml
file.
<resource-ref>
<res-ref-name>jdbc/springdb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
The automated fix will also add the JNDI name to the bindings file.
For the preceding example, jdbc/springdb is used
as the resource reference name and the JNDI name.
If the Spring bean is coded as:
<bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/springdb"/>
<property name="lookupOnStartup" value="false"/>
<property name="cache" value="true"/>
<property name="proxyInterface" value="javax.sql.DataSource"/>
</bean>
The automated fix will use jdbc/springdb as the
resource reference and JNDI name in the deployment descriptor
and bindings files. It would also modify the Spring XML file and
change the jndiName property to:
<property name="jndiName" value="java:comp/env/jdbc/springdb"/>
For additional information, see: