2016-07-31 3 views
0
으로 캐스팅 할 수 없습니다.

Wildfly 8.2.1에서 실행되는 EJB 상태없는 프로젝트 (helloworld)가 있습니다. Java 1.7 및 클라이언트 응용 프로그램이있는 최종 서버 자바 1.8. 오류가 발생했습니다. 스레드에서 당신java.lang.ClassCastException : org.jboss.ejb.client.naming.ejb.EjbNamingContext를

예외 감사 "주"java.lang.ClassCastException가이 : org.jboss.ejb.client.naming.ejb.EjbNamingContext는 닷컴에서 com.aburak.sb.SessionBeanRemote으로 캐스팅 할 수 없습니다. aburak.sb.Driver.main (Driver.java:15는)

이 클라이언트 응용 프로그램을

public class Driver { 
    public static void main(String[] args) throws NamingException { 
      Context context=Driver.getInitialContext(); 
      SessionBeanRemote sbRemote= (SessionBeanRemote) context.lookup("ejb:SessionBean/SessionBean!com.aburak.sb.SessionBeanRemote"); 
      sbRemote.sessionBeanMethod(); 
    } 
    public static Context getInitialContext() throws NamingException{ 
     Properties properties = new Properties(); 
     properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
     properties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
     properties.setProperty(Context.PROVIDER_URL, "http://127.0.0.1:8080"); 

     return new InitialContext(properties); 
    } 
} 

원격 BeanSession

내 드라이버 클래스입니다
@Stateless 
@TransactionManagement(TransactionManagementType.BEAN) 
public class SessionBean implements SessionBeanRemote, SessionBeanLocal{ 

private static final long serialVersionUID = -7201692010023776738L; 

@Override 
public void sessionBeanMethod() { 
    System.out.println("SessionBean executed..."); 

} 

SessionBeanRemote

@Remote 
public interface SessionBeanRemote extends SessionBeanIF{ 

} 

SessionBeanIF

public interface SessionBeanIF extends Serializable{ 
public void sessionBeanMethod(); 
} 

(SessionBeanLocal 정확한 같은 @Local 주석을 제외하고 SessionBeanRemote이다)이 클라이언트 드라이브 클래스

public class Driver { 
    public static void main(String[] args) throws NamingException { 
      Context context=Driver.getInitialContext(); 
      SessionBeanRemote sbRemote= (SessionBeanRemote) context.lookup("ejb:SessionBean/SessionBean!com.aburak.sb.SessionBeanRemote"); 
      sbRemote.sessionBeanMethod(); 
    } 
    public static Context getInitialContext() throws NamingException{ 
     Properties properties = new Properties(); 
     properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
     properties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
     properties.setProperty(Context.PROVIDER_URL, "http://127.0.0.1:8080"); 

     return new InitialContext(properties); 
    } 
} 
입니다

SessionBeanClient >>의 pom.xml

<dependencies> 
    <dependency> 
     <groupId>org.wildfly</groupId> 
     <artifactId>wildfly-ejb-client-bom</artifactId> 
     <version>8.2.1.Final</version> 
     <type>pom</type> 
    </dependency> 
    <dependency> 
     <groupId>org.wildfly</groupId> 
     <artifactId>wildfly-jms-client-bom</artifactId> 
     <version>8.2.1.Final</version> 
     <type>pom</type> 
    </dependency> 
</dependencies> 

세션빈 >>의 pom.xml

<dependency> 
    <groupId>javax.ejb</groupId> 
    <artifactId>javax.ejb-api</artifactId> 
    <version>3.2</version> 
    <scope>compile</scope> 
</dependency> 

나는 this tutorial video 따라하지만 난 그것을 뭔가 애플리케이션 서버 등 을 변경하고도 오류가 this을 찾을 검색하지만, 내 문제를 해결하지 못했습니다.

이 내 Package explorer

감사합니다 네 당신의 도움이됩니다.

답변

0

원격 호출 경로가 잘못되었습니다. wildfly 서버에 ejb를 배포 할 때 서버 로그에서 전체 경로를 살펴보십시오. 그것은 당신이 클라이언트의 자원 폴더에 프로퍼티 파일 이름 'jboss-ejb-client.properties'을 필요

ejb:/ejb-1.0-SNAPSHOT/SessionBean!com.thanhnn.training.SessionBeanRemote 

처럼 보일 것입니다.

remote.connections=default 
remote.connection.default.host=localhost 
remote.connection.default.port=8080 
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false 
remote.connection.default.username=your-user-name 
remote.connection.default.password=your-pass-word 

는 응용 프로그램 사용자, 실행 추가 user.bat을 만들거나 $ {JBOSS_HOME}/빈에서 add-user.sh 프로세스를 따르십시오.클라이언트와 서버의 핸드 셰이크 프로세스에 대한

, 당신은 치어 파일에 다음과 같은 종속성이 필요합니다 마지막으로

<dependency> 
     <groupId>org.jboss.spec.javax.transaction</groupId> 
     <artifactId>jboss-transaction-api_1.2_spec</artifactId> 
     <version>1.0.1.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.spec.javax.ejb</groupId> 
     <artifactId>jboss-ejb-api_3.2_spec</artifactId> 
     <version>1.0.0.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss</groupId> 
     <artifactId>jboss-ejb-client</artifactId> 
     <version>2.1.6.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.xnio</groupId> 
     <artifactId>xnio-api</artifactId> 
     <version>3.4.0.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.xnio</groupId> 
     <artifactId>xnio-nio</artifactId> 
     <version>3.4.0.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.remoting</groupId> 
     <artifactId>jboss-remoting</artifactId> 
     <version>4.0.21.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.sasl</groupId> 
     <artifactId>jboss-sasl</artifactId> 
     <version>1.0.5.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.marshalling</groupId> 
     <artifactId>jboss-marshalling-river</artifactId> 
     <version>1.4.11.Final</version> 
    </dependency> 

그리고, 클라이언트

public static void main(String[] args) throws NamingException { 
    Context context=Driver.getInitialContext(); 
    SessionBeanRemote sbRemote= (SessionBeanRemote) context.lookup("ejb:/ejb-1.0-SNAPSHOT/SessionBean!com.thanhnn.training.SessionBeanRemote"); 
    sbRemote.sessionBeanMethod(); 
} 
public static Context getInitialContext() throws NamingException{ 
    Properties properties = new Properties(); 
    properties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 

    return new InitialContext(properties); 
} 

주에 대한 코드를 : 당신은 필요가 없습니다 인터페이스에서 메서드를 public으로 선언하려면

관련 문제