普通java类客户端访问EJB SessionBean总是显示Connection refused
我用的是JBoss7.1.1 + Myeclipse10 + EJB3.0 +jdk1.7
会话bean代码:
package com.service;
import javax.ejb.Remote;
@Remote
public interface HelloWorldBeanRemote {
public String sayHello(String name);
}
package com.service;
import javax.ejb.Stateless;
@Stateless
public class HelloWorldBean implements HelloWorldBeanRemote {
@Override
public String sayHello(String name) {
// TODO Auto-generated method stub
return name+",Hello World";
}
}
java客户端代码:
import java.util.Properties;
import javax.naming.InitialContext;
import com.service.HelloWorldBean;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url","localhost:4447");
props.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
try{
InitialContext ctx = new InitialContext(props);
HelloWorldBean helloworld = (HelloWorldBean) ctx.lookup("HelloWorldBean/remote");
System.out.println(helloworld.sayHello("Jhon"));
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
客户端我BuildPath里添加了EJB的接口,还添加了jboss-client.jar,jnp-client.jar,jbossall-client.jar
请大神指点一下,挺急的谢谢!在线等!