2017-10-11 5 views
0

EJB 3.0에 Juboss 5와 함께 helloworld 앱을 만들었습니다. 클라이언트 클래스 EjbClientApplication을 실행하려고하면 예외를 throw합니다.클라이언트 클래스를 실행하는 동안 EJB 프로젝트의 CommunicationException : 다음 url에 연결할 수 없습니다. localhost : 1099

자주 예외가 발생합니다. 나는 그것에 대해 많은 일을 해왔지만, EJB에 익숙하지 않아서 찾지 못했습니다.

예외 :

javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]] at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1763) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:693) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686) at javax.naming.InitialContext.lookup(InitialContext.java:392) at com.hex.client.EjbClientApplication.main(EjbClientApplication.java:28) Caused by: javax.naming.CommunicationException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:335) at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1734) ... 4 more Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:305) ... 5 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:529) at org.jnp.interfaces.TimedSocketFactory.createSocket (TimedSocketFactory.java:97) at org.jnp.interfaces.TimedSocketFactory.createSocket (TimedSocketFactory.java:82) at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:301) ... 5 more

JBoss 서버 포트 127.0.0.1:10001 함께하지만 난이 URL 127.0.0.1:1099이 RYT입니다 맞추려고?

서버 등록 :

  • 주소 : 127.0.0.1
  • 포트 : 8080
  • JNDI 포트 : 1099

MyCode :이 코드는 하나의 EJB 프로젝트 구성

RemoteInterfaceClass :

package com.hex.statelessbean; 

import javax.ejb.Remote; 

@Remote 

public interface StatelessSessionBeanRemote { 

    public String displayMessage(); 
} 

StatelessBean :

/** 
* Session Bean implementation class StatelessSessionBean 
*/ 

package com.hex.statelessbean; 

import javax.ejb.Stateless; 

@Stateless 

public class StatelessSessionBean implements StatelessSessionBeanRemote { 

/** 
* Default constructor. 
*/ 
public StatelessSessionBean() { 
    // TODO Auto-generated constructor stub 
} 

@Override 
public String displayMessage() { 
    // TODO Auto-generated method stub 
    return "Hello world"; 
} 

}

클라이언트 :

package com.hex.client; 

import java.util.Properties; 

import javax.naming.InitialContext; 
import javax.naming.NamingException; 

import com.hex.statelessbean.StatelessSessionBeanRemote; 

public class EjbClientApplication { 

public static void main(String[] args) { 
    try { 
    Properties props = new Properties(); 
    props.setProperty("java.naming.factory.initial", 
    "org.jnp.interfaces.NamingContextFactory"); 
    props.setProperty("java.naming.factory.url.pkgs", 
    "org.jboss.naming"); 
    props.setProperty("java.naming.provider.url", "localhost:1099"); 

    InitialContext ctx = new InitialContext(props); 
    StatelessSessionBeanRemote bean = (StatelessSessionBeanRemote) ctx 
    .lookup("StatelessSessionBean/remote"); 
    System.out.println("Message from Bean :" + bean.displayMessage()); 
    } catch (NamingException e) { 
    e.printStackTrace(); 
    } 

    } 
} 

답변

0

localhost:1099 to jnp://localhost:1099org.jboss.naming to org.jboss.naming:org.jnp.interfaces을 변경하고 ejb의 이름을 확인하십시오. 주석 @RemoteBinding을 사용하면 ejb의 이름을 지정할 수 있습니다. 포트 오프셋이 있습니까?

+0

나는 변경 사항을 적용했지만 동일한 예외가 발생하더라도. –

+0

@ JayanthiM 서버 구성의 JNDI 포트는 무엇입니까? 서버 로그 또는 JMX 콘솔에서 EJB를 본 적이 있습니까? java.naming.factory.url.pkgs 값을 org.jboss.naming.client로 변경하려고 시도 할 수 있습니까? – awagenhoffer

+0

서버 구성에서 JNDI 포트가 1099이고, 포트가 8080이며, org.jboss.naming : org.jnp.interfaces로 값이 변경되었지만 자주이 예외가 발생합니다. javax.naming.CommunicationException : 로컬 호스트 : 1099 및 발견 오류가 발생하여 오류 : javax.naming.CommunicationException : 수신 시간 초과 [루트 예외가 java.net.SocketTimeoutException : 수신 시간 초과] –

0
Corrected Code: 

    **Interface class:** 


    package com.hex.statelessbean; 

    import javax.ejb.Remote; 

    @Remote 
    public interface StatelessSessionBeanRemote { 

     public String displayMessage(); 
    } 


    **Stateless Bean class:** 

    package com.hex.statelessbean; 

    import javax.ejb.Stateless; 

    /** 
    * Session Bean implementation class StatelessSessionBean 
    */ 
    @Stateless 
    public class StatelessSessionBean implements StatelessSessionBeanRemote { 

     /** 
     * Default constructor. 
     */ 
     public StatelessSessionBean() { 
      // TODO Auto-generated constructor stub 
      System.out.println("************* Calling from Default constructor ******************"); 
     } 

     @Override 
     public String displayMessage() { 
      // TODO Auto-generated method stub 
      System.out.println("************* Calling from displayMessage() ******************"); 
      return "Hello world"; 
     } 

    } 


**Client class:** 


package com.hex.client; 

import java.util.Properties; 

import javax.naming.Context; 
import javax.naming.InitialContext; 
import javax.naming.NamingException; 

import com.hex.statelessbean.StatelessSessionBeanRemote; 

public class EjbClientApplication { 

    /** 
    * @param args 
    * @throws NamingException 
    */ 

    public static void main(String[] args) { 
     try { 
      Properties properties = new Properties(); 
      properties.setProperty("java.naming.factory.initial", 
        "org.jnp.interfaces.NamingContextFactory"); 
      properties.setProperty("java.naming.factory.url.pkgs", 
        "org.jboss.naming:org.jnp.interfaces"); 
      properties.setProperty("java.naming.provider.url", 
        "jnp://localhost:1099"); 
     InitialContext ctx = new InitialContext(properties); 
     StatelessSessionBeanRemote bean = (StatelessSessionBeanRemote) ctx 
     .lookup("StatelessSessionBean/remote"); 
     System.out.println("Message from Bean :" + bean.displayMessage()); 
     } catch (NamingException e) { 
     e.printStackTrace(); 
     } 
     } 
} 


**LookUp:** 

Message from Bean :Hello world