0

I am facing problem as the actual imported java file is not being called. Please have a look of my code :-

    import javax.naming.Context;
    import javax.naming.InitialContext;
    .....
   public class ABC{
   .....
  1.      Context lContext = null;
  2.        ObjectDataSourceFactory lSource = null;
  3.      try
  4.       {
  5.           lContext = new InitialContext();
  6.           lSource = ((ObjectDataSourceFactory)lContext.lookup(....));
     }
        catch (Exception e)
    {

    }

The Problem I am facing here is : when flow control goes into line number 6. it calls the "lookup method" from "SelectorContext.java" but not from "InitialContext.java", I have found this with the help of DEBUGGING mode in eclipse . As a result it cannot find the proper JNDI and gives exception. FYI.. My code is running on Tomcat6. I have set the classpath of jar files from my JRE1.6 and so the JDK.

Can someone please suggest me - how can I know from which JAR this "SelectorContext.java" is being called and how to make it to Look into the InitialContext.class which is present inside RT.JAR, if I am not wrong ?

4

1 回答 1

1

你的理解不正确。SelectorContext 是 tomcat 的 JNDI 实现之一。

通过将 java.naming.factory.initial 设置为系统变量,可以选择使用外部 JNDI 上下文。这是由 Tomcat (javaURLContextFactory) 设置的,以提供它自己的 JNDI 服务。

当您调用 new InitialContext() 时,JVM 会查看是否存在用户提供的命名工厂,如果可用,则 JVM 调用 initialFactory.getInitialContext 以获取自定义 JNDI 实现并将其设为默认值,所有对 context 的方法调用依次路由到自定义实现。

在你的情况下,调用 SelectorContext 是正确的,看看你是否有必要的配置来在 JNDI 中拥有资源。

于 2013-10-16T16:28:54.207 回答