【求救】关于Tomcat中Web客户端,连接JBOSS中EJB3服务端出现的问题
服务端(test):
HelloWorld接口:
package com.test.ejb3;public interface HelloWorld { public String SayHello(String name);}
package com.test.ejb3.impl;import com.test.ejb3.HelloWorld;import javax.ejb.Local;import javax.ejb.Remote;import javax.ejb.Stateless;@Stateless@Remote (HelloWorld.class)@Local (HelloWorld.class)public class HelloWorldBean implements HelloWorld { public String SayHello(String name) { return name+":Hello~~!"; }}
package com.web.util;import java.util.Properties;import javax.naming.InitialContext;import javax.naming.NamingException;public class EJBFactory { public static Object getEJB(String jndipath) { try { Properties props = new Properties(); props.setProperty("javax.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); props.setProperty("javax.naming.provider.url", "jnp://127.0.0.1:1099"); props.setProperty("javax.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); props.setProperty("jnp.disableDiscovery", "true"); InitialContext ctx = new InitialContext(props); return ctx.lookup(jndipath); } catch (NamingException e) { e.printStackTrace(); } return null; }}
<%@ page contentType="text/html; charset=GBK"%><%@ page import="com.test.ejb3.HelloWorld,com.web.util.EJBFactory;"%><% HelloWorld helloWorld = (HelloWorld) EJBFactory.getEJB("HelloWorldBean/remote"); out.println(helloWorld.SayHello("Good")+"<br/>");%>
javax.naming.NameNotFoundException: Name HelloWorldBean is not bound in this Context
props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); props.setProperty("java.naming.provider.url", "jnp://127.0.0.1:1099"); props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
javax.naming.CommunicationException: Could not obtain connection to any of these urls: 127.0.0.1:1099 [Root exception is javax.naming.CommunicationException: Failed to connect to server 127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server 127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]]
http://u.115.com/file/f6f9a05f70