繁体   English   中英

如何创建EJB 3.2无状态Bean项目并在Wildfly 8上运行它?

[英]How to create EJB 3.2 Stateless Bean Project and Running it on Wildfly 8?

我正在尝试创建EJB 3.2无状态Bean项目,但到目前为止仍然无济于事。 我希望有人能帮助我。

这是我的日食上的EJB Project结构:

在此处输入图片说明

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

Test.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。

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

线程“主”中的异常java.lang.IllegalStateException:EJBCLIENT000025:没有可用的EJB接收器来处理org.jboss.ejb.client.EJBClientInvocationContext@28d72e3f的调用上下文org.jboss.ejb.client.EJBClientInvocationContext@28d72e3f的组合org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)处的.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:749)org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java :186)

有人可以帮忙吗?

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

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

  2. 根据这篇文章 ,对于Wildfly 8远程端口已被纳入到8080端口,所以我只需要改变remote.connection.default.port到8080 jboss-ejb-client.properties

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM