类 SimpleNamingContextBuilder
- java.lang.Object
- org.springframework.mock.jndi.SimpleNamingContextBuilder
- 所有已实现的接口:
InitialContextFactoryBuilder
@Deprecated public class SimpleNamingContextBuilder extends Object implements InitialContextFactoryBuilder
已过时。Deprecated as of Spring Framework 5.2 in favor of complete solutions from third parties such as Simple-JNDISimple implementation of a JNDI naming context builder.Mainly targeted at test environments, where each test case can configure JNDI appropriately, so that
new InitialContext()
will expose the required objects. Also usable for standalone applications, e.g. for binding a JDBC DataSource to a well-known JNDI location, to be able to use traditional Java EE data access code outside of a Java EE container.There are various choices for DataSource implementations:
SingleConnectionDataSource
(using the same Connection for all getConnection calls)DriverManagerDataSource
(creating a new Connection on each getConnection call)- Apache's Commons DBCP offers
org.apache.commons.dbcp.BasicDataSource
(a real pool)
Typical usage in bootstrap code:
SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder(); DataSource ds = new DriverManagerDataSource(...); builder.bind("java:comp/env/jdbc/myds", ds); builder.activate();
Note that it's impossible to activate multiple builders within the same JVM, due to JNDI restrictions. Thus to configure a fresh builder repeatedly, use the following code to get a reference to either an already activated builder or a newly activated one:SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder(); DataSource ds = new DriverManagerDataSource(...); builder.bind("java:comp/env/jdbc/myds", ds);
Note that you should not callactivate()
on a builder from this factory method, as there will already be an activated one in any case.An instance of this class is only necessary at setup time. An application does not need to keep a reference to it after activation.
- 作者:
- Juergen Hoeller, Rod Johnson
- 另请参阅:
emptyActivatedContextBuilder()
,bind(String, Object)
,activate()
,SimpleNamingContext
,SingleConnectionDataSource
,DriverManagerDataSource
构造器概要
构造器 构造器 说明 SimpleNamingContextBuilder()
已过时。
方法概要
所有方法 静态方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 void
activate()
已过时。Register the context builder by registering it with the JNDI NamingManager.void
bind(String name, Object obj)
已过时。Bind the given object under the given name, for all naming contexts that this context builder will generate.void
clear()
已过时。Clear all bindings in this context builder, while keeping it active.InitialContextFactory
createInitialContextFactory(Hashtable<?,?> environment)
已过时。Simple InitialContextFactoryBuilder implementation, creating a new SimpleNamingContext instance.void
deactivate()
已过时。Temporarily deactivate this context builder.static SimpleNamingContextBuilder
emptyActivatedContextBuilder()
已过时。If no SimpleNamingContextBuilder is already configuring JNDI, create and activate one.static SimpleNamingContextBuilder
getCurrentContextBuilder()
已过时。Checks if a SimpleNamingContextBuilder is active.
构造器详细资料
SimpleNamingContextBuilder
public SimpleNamingContextBuilder()
已过时。
方法详细资料
getCurrentContextBuilder
@Nullable public static SimpleNamingContextBuilder getCurrentContextBuilder()
已过时。Checks if a SimpleNamingContextBuilder is active.- 返回:
- the current SimpleNamingContextBuilder instance, or
null
if none
emptyActivatedContextBuilder
public static SimpleNamingContextBuilder emptyActivatedContextBuilder() throws NamingException
已过时。If no SimpleNamingContextBuilder is already configuring JNDI, create and activate one. Otherwise take the existing activated SimpleNamingContextBuilder, clear it and return it.This is mainly intended for test suites that want to reinitialize JNDI bindings from scratch repeatedly.
- 返回:
- an empty SimpleNamingContextBuilder that can be used to control JNDI bindings
- 抛出:
NamingException
activate
public void activate() throws IllegalStateException, NamingException
已过时。Register the context builder by registering it with the JNDI NamingManager. Note that once this has been done,new InitialContext()
will always return a context from this factory. Use theemptyActivatedContextBuilder()
static method to get an empty context (for example, in test methods).- 抛出:
IllegalStateException
- if there's already a naming context builder registered with the JNDI NamingManagerNamingException
deactivate
public void deactivate()
已过时。Temporarily deactivate this context builder. It will remain registered with the JNDI NamingManager but will delegate to the standard JNDI InitialContextFactory (if configured) instead of exposing its own bound objects.Call
activate()
again in order to expose this context builder's own bound objects again. Such activate/deactivate sequences can be applied any number of times (e.g. within a larger integration test suite running in the same VM).- 另请参阅:
activate()
clear
public void clear()
已过时。Clear all bindings in this context builder, while keeping it active.
bind
public void bind(String name, Object obj)
已过时。Bind the given object under the given name, for all naming contexts that this context builder will generate.- 参数:
name
- the JNDI name of the object (e.g. "java:comp/env/jdbc/myds")obj
- the object to bind (e.g. a DataSource implementation)
createInitialContextFactory
public InitialContextFactory createInitialContextFactory(@Nullable Hashtable<?,?> environment)
已过时。Simple InitialContextFactoryBuilder implementation, creating a new SimpleNamingContext instance.