Bean类:
- Java code
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;
}
}
客户端:
- Java code
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已经部署成功
但是执行就是报错
- Java code
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 moreCaused by: java.io.EOFException at java.io.DataInputStream.readByte(DataInputStream.java:250) at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:228) ... 7 more
------解决方案--------------------
友情帮顶了,解决就好,