From 6427a1bd9e59576f6d1bf97bb8ad90a1d43e8fdb Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Sat, 2 Jul 2011 21:26:30 +0000 Subject: [PATCH] Return null from JndiPropertySource on lookup failure Issue: SPR-8490 git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4646 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../jndi/JndiPropertySource.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/org.springframework.context/src/main/java/org/springframework/jndi/JndiPropertySource.java b/org.springframework.context/src/main/java/org/springframework/jndi/JndiPropertySource.java index 2655e9a83eb..f0688a35c2a 100644 --- a/org.springframework.context/src/main/java/org/springframework/jndi/JndiPropertySource.java +++ b/org.springframework.context/src/main/java/org/springframework/jndi/JndiPropertySource.java @@ -25,8 +25,11 @@ import javax.naming.NamingException; import org.springframework.core.env.PropertySource; /** - * {@link PropertySource} implementation that reads properties from - * a JNDI {@link Context}. + * {@link PropertySource} implementation that reads properties from a JNDI + * {@link Context}. All properties retrieved through {@link #getProperty(String)} will + * automatically be prefixed with "java:comp/env/" when executing the actual + * {@link Context#lookup(String)} call. This default can be overridden using + * {@link #setJndiPrefix(String)} property. * * @author Chris Beams * @author Juergen Hoeller @@ -86,14 +89,21 @@ public class JndiPropertySource extends PropertySource { } /** - * Look up and return the given name from the source JNDI {@link Context}. + * {@inheritDoc} + *

This implementation looks up and returns the given name from the source JNDI + * {@link Context}. If a {@link NamingException} is thrown during the call to + * {@link Context#lookup(String)}, returns {@code null} and issue a DEBUG-level log + * statement with the exception message. */ @Override - public Object getProperty(String name) throws JndiLookupFailureException { + public Object getProperty(String name) { try { - return this.source.lookup(name); + Object value = this.source.lookup(name); + logger.debug("Context#lookup(" + name + ") returned: [" + value + "]"); + return value; } catch (NamingException ex) { - throw new JndiLookupFailureException("unable to look up name" + name, ex); + logger.debug("Context#lookup(" + name + ") threw NamingException with message: " + ex.getMessage()); + return null; } }