gpt4 book ai didi

java - 如何创建 EJB 3.2 Stateless Bean 项目并在 Wildfly 8 上运行它?

转载 作者:行者123 更新时间:2023-11-30 03:37:29 25 4
gpt4 key购买 nike

我正在尝试创建 EJB 3.2 Stateless Bean 项目,但到目前为止仍然无济于事。我希望任何人都可以帮助我。

这是我的 eclipse 上的 EJB 项目结构:

enter image description here

SLBean.java

package com.example.ejbtest;

import javax.ejb.Stateless;


@Stateless
public class SLBean implements SLBeanRemote {

public SLBean() {
}

@Override
public String sayHello() {
return "Hello World !!!";
}

}

SLBeanRemote.java

package com.example.ejbtest;

import javax.ejb.Remote;

@Remote
public interface SLBeanRemote {
public String sayHello();
}

jboss-ejb-client.properties

endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default

remote.connection.default.host=localhost
remote.connection.default.port=4447
remote.connection.default.username=user1
remote.connection.default.password=password
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

测试.java

package com.example.ejbtest;

import java.util.Properties;

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

public class Test {

public static void main(String[] args) {
Context context;
try {
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
properties.put("jboss.naming.client.ejb.context", true);
context = new InitialContext(properties);

String appName = "";
String moduleName = "EJBTest";
String distinctName = "";
String beanName = SLBean.class.getSimpleName();
String viewClassName = SLBeanRemote.class.getName();

String ejbString = "ejb:" + appName + "/" + moduleName + "/"
+ distinctName + "/" + beanName + "!" + viewClassName;

System.out.println(ejbString);

SLBeanRemote remote = (SLBeanRemote) context.lookup(ejbString);
System.out.println(remote.sayHello());

} catch (NamingException e) {
e.printStackTrace();
}
}
}

因此,当我通过 Eclipse 在 Wildfly Server 上运行 EJBTest 项目后,我运行 Test.java 作为客户端程序来连接到远程无状态 bean。

但是我得到的是这样的错误:

Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:EJBTest, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@28d72e3f at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:749) at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116) at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)

有人可以帮忙吗?

最佳答案

好的,我找到答案了。我犯了两个错误:

  1. 我没有将 jboss-ejb-client.properties 文件放在正确的位置,即源文件夹的根目录 (ejbModule)。

  2. 根据this article ,Wildfly 8的远程端口已合并到端口8080,所以我只需要将jboss-中的remote.connection.default.port更改为8080即可ejb-client.properties.

关于java - 如何创建 EJB 3.2 Stateless Bean 项目并在 Wildfly 8 上运行它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27519075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com