First and foremost, your tests typically should not rely on JNDI being present in a test environment.
The whole point of using JndiObjectFactoryBean
is so that you can decouple your application from a direct dependency on JNDI, using dependency injection of components instead.
With that in mind, I would highly recommend that you never inject an instance of JndiObjectFactoryBean
into one of your application components. Instead, you should really be injecting the object returned by the JndiObjectFactoryBean
into your components. By doing so, you can then configure a mock or stub of your component when writing unit and integration tests, thereby avoiding the need for JNDI for testing.
Now, if for some very good reason you simply must rely directly on JNDI, Spring does provide a mechanism for setting up an in-memory JNDI context. See the Javadoc for SimpleNamingContextBuilder for details.