【发布时间】:2016-12-05 21:26:33
【问题描述】:
我有一个 EJB 无状态项目 (helloworld) 在 Wildfly 8.2.1 Final 服务器下运行,带有 java 1.7 和一个带有 java 1.8 的客户端应用程序。我收到一个错误。谢谢
线程“主”java.lang.ClassCastException 中的异常: org.jboss.ejb.client.naming.ejb.EjbNamingContext 不能转换为 com.aburak.sb.SessionBeanRemote 在 com.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{
}
(SessionBeanLocal 与 SessionBeanRemote 完全相同,但 @Local 注解除外)
SessionBeanIF
public interface SessionBeanIF extends Serializable{
public void sessionBeanMethod();
}
这是客户端 Drive 类
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>
SessionBean >> 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
感谢四位您的帮助。
【问题讨论】:
标签: java eclipse maven ejb wildfly