我们还有没几天就学习了,先收藏你的问题!到时候我也看看!!关注啦!
顺便说下,我看我们刚学的OOAD和XML和你其中的代码很相似啊!!

解决方案 »

  1.   

    没有人回复啊?
    大概知道是这样的错误了,也跑起来了,可是还有问题不理解
    我每次在程序中写InitialContext initialContext = new InitialContext(env);
    Object homeObject = initialContext.lookup( "******" );
    这样2句的时候,不管在Weblgic还是在jboss里,一定抛出异常。
    但是加上Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      env.put(Context.PROVIDER_URL, "127.0.0.1:1099");
     就不会了,而1099是JBOss的Jndi服务端口,但是weblogic的是多少?
      

  2.   

    因为你没有在同一个环境下调用,设置上下文对象环境,
    String url = "t3://127.0.0.1:7001";
            String user = null;
            String password = null;
            Properties properties;
            try {
                properties = new Properties();
                properties.put(Context.INITIAL_CONTEXT_FACTORY,
                               "weblogic.jndi.WLInitialContextFactory");
                properties.put(Context.PROVIDER_URL, url);
                if (user != null) {
                    properties.put(Context.SECURITY_PRINCIPAL, user);
                    properties.put(Context.SECURITY_CREDENTIALS,
                                   password == null ? "" : password);
                }
              InitialContext initialContext =  new javax.naming.InitialContext(properties);
     Object homeObject = 
                initialContext.lookup( "InterestCalculator" );
             
             // get InterestCalculatorHome interface
             InterestCalculatorHome calculatorHome = 
                ( InterestCalculatorHome )
                   PortableRemoteObject.narrow( homeObject, 
                      InterestCalculatorHome.class );         
             
             // create InterestCalculator EJB instance
             calculator = calculatorHome.create();
      

  3.   

    再写个文件:jndi.properties
    内容如下:
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
    java.naming.provider.url=localhost和META-INF目录放在同一目录下。然后再正确打包,部署,应该有类似于下面的提示:
    00:09:47,062 INFO  [EjbModule] Deploying CabinEJB
    00:09:47,203 INFO  [EjbModule] Deploying CustomerEJB
    00:09:47,234 INFO  [EjbModule] Deploying CreditCardEJB
    00:09:47,250 INFO  [EjbModule] Deploying AddressEJB
    00:09:47,265 INFO  [EjbModule] Deploying PhoneEJB
    00:09:47,281 INFO  [EjbModule] Deploying ShipEJB
    00:09:47,296 INFO  [EjbModule] Deploying ShipBMPEJB
    00:09:47,328 INFO  [EjbModule] Deploying CruiseEJB
    00:09:47,343 INFO  [EjbModule] Deploying ReservationEJB
    00:09:47,359 INFO  [EjbModule] Deploying TravelAgentEJB
    00:09:47,406 INFO  [EjbModule] Deploying ProcessPaymentEJB
    00:09:47,406 INFO  [EjbModule] Deploying ReservationProcessorEJB
    =====================================
    然后在客户程序里面就可以直接使用:Context ctx = new InitialContext();就可以得到正确的Context了,不用再传个Properties参数。