Bean类:package com.huawei.ejb;import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;@Stateless(mappedName="HelloBean")
@Remote(Hello.class)
@Local(Hello.class)
public class HelloBean implements Hello {

public String say(String name) {
return "Hello " + name;
}}
客户端:package com.huawei.ejb.client;import java.util.Properties;import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;import com.huawei.ejb.Hello;public class HelloEjbClient {

public static void main(String[] args) throws NamingException{
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
Context context = new InitialContext(properties);
Hello hello = (Hello)context.lookup("HelloBean/remote");
String returnValue = hello.say("renci");
System.out.println(returnValue);
}}
weblogic已经部署成功但是执行就是报错Exception in thread "main" javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is: 
java.io.EOFException]
at weblogic.jrmp.Context.lookup(Context.java:189)
at weblogic.jrmp.Context.lookup(Context.java:195)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.huawei.ejb.client.HelloEjbClient.main(HelloEjbClient.java:18)
Caused by: java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is: 
java.io.EOFException
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:286)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at weblogic.jrmp.Context.lookup(Context.java:185)
... 3 more
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:250)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:228)
... 7 more

解决方案 »

  1.   

    找到答案了,将WebLogic.jar放在classpath的第一位就可以解决这个问题但是现在又遇到问题了Exception in thread "main" javax.naming.NameNotFoundException: While trying to lookup 'HelloBean.remote' didn't find subcontext 'HelloBean'. Resolved '' [Root exception is javax.naming.NameNotFoundException: While trying to lookup 'HelloBean.remote' didn't find subcontext 'HelloBean'. Resolved '']; remaining name 'HelloBean/remote'
            at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:234)
            at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:348)
            at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:259)
            at weblogic.jndi.internal.ServerNamingNode_1032_WLStub.lookup(Unknown Source)
            at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:405)
            at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:393)
            at javax.naming.InitialContext.lookup(InitialContext.java:392)
            at ejbtest.Main.main(Main.java:35)
    Caused by: javax.naming.NameNotFoundException: While trying to lookup 'HelloBean.remote' didn't find subcontext 'HelloBean'. Resolved ''
            at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
            at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:247)
            at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:182)
            at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
            at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
            at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:589)
            at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230)
            at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:477)
            at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
            at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
            at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:473)
            at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
            at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
            at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    Java Result: 1
    WebLogic已经部署成功了,而其配置的数据源都可以找到,ejb怎么就找不到呢???
      

  2.   

    问题搞定,原因是没有写weblogic-ejb-jar.xml
    客户端也写错了/*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */package ejbtest;import com.renci.ejb.Hello;
    import java.sql.SQLException;
    import java.util.Properties;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;/**
     *
     * @author klutz
     */
    public class Main {
        public static void main(String[] args) throws NamingException, SQLException{
            Properties properties = new Properties();
            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
            properties.setProperty(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
            properties.setProperty(Context.SECURITY_PRINCIPAL, "weblogic");
            properties.setProperty(Context.SECURITY_CREDENTIALS, "renci418037077");
            Context context = new InitialContext(properties);
            Hello hello = (Hello)context.lookup("HelloBean#com.renci.ejb.Hello");
            String returnValue = hello.say("renci");
            System.out.println(returnValue);
        }
    }
      

  3.   

    不太清楚,是配置开发环境还是Weblogic运行环境了。
             找到答案了,将WebLogic.jar放在classpath的第一位就可以解决这个问题