This rule flags the Spring
jndi-lookup
element
in Spring configuration files when the following conditions are met.
- The project is a web project
- The project attribute
proxy-interface
value is
javax.sql.DataSource
- The attribute
jndi-name
value meets any of the following conditions:
- it starts with
java:comp/env/
, or
- the
web.xml
file does not contain a
<resource-ref>
with a
<res-ref-name>
that is equal to the
jndi-name
(without
java:comp/env/
), or
- the web.xml does not exist
This element is flagged in order to ensure that corresponding elements
in the
web.xml
, WebSphere traditional and Liberty bindings files are properly configured.
This example Spring configuration will be flagged because the
jndi-name
value
starts with
java:comp/env/
.
<jee:jndi-lookup id="myDataSource"
jndi-name="java:comp/env/jdbc/springdb"
proxy-interface="javax.sql.DataSource"/>
To resolve this issue, The automated fix will make the following updates:
- Ensure the jndi-name does not start with java:comp/env/
- Add a
<resource-ref>
elemnt to
web.xml
with a
<res-ref-name>
that is equal to the
jndi-name
(without
java:comp/env/
)
- Add or update the WebSphere bindings files with the JNDI name reference.
For additional information, see: