/* * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.jndi; import javax.naming.NamingException; import org.springframework.core.env.PropertySource; /** * {@link PropertySource} implementation that reads properties from an underlying Spring * {@link JndiLocatorDelegate}. * *
By default, the underlying {@code JndiLocatorDelegate} will be configured with its * {@link JndiLocatorDelegate#setResourceRef(boolean) "resourceRef"} property set to * {@code true}, meaning that names looked up will automatically be prefixed with * "java:comp/env/" in alignment with published * JNDI * naming conventions. To override this setting or to change the prefix, manually * configure a {@code JndiLocatorDelegate} and provide it to one of the constructors here * that accepts it. The same applies when providing custom JNDI properties. These should * be specified using {@link JndiLocatorDelegate#setJndiEnvironment(java.util.Properties)} * prior to construction of the {@code JndiPropertySource}. * *
Note that {@link org.springframework.web.context.support.StandardServletEnvironment
* StandardServletEnvironment} includes a {@code JndiPropertySource} by default, and any
* customization of the underlying {@link JndiLocatorDelegate} may be performed within an
* {@link org.springframework.context.ApplicationContextInitializer
* ApplicationContextInitializer} or {@link org.springframework.web.WebApplicationInitializer
* WebApplicationInitializer}.
*
* @author Chris Beams
* @author Juergen Hoeller
* @since 3.1
* @see JndiLocatorDelegate
* @see org.springframework.context.ApplicationContextInitializer
* @see org.springframework.web.WebApplicationInitializer
* @see org.springframework.web.context.support.StandardServletEnvironment
*/
public class JndiPropertySource extends PropertySource