“线程中的异常”;“主要”;java.lang.IllegalStateException:没有可处理的EJB接收器——jboss-as-7.1.1.Final

“线程中的异常”;“主要”;java.lang.IllegalStateException:没有可处理的EJB接收器——jboss-as-7.1.1.Final,java,android,eclipse,ejb,jboss7.x,Java,Android,Eclipse,Ejb,Jboss7.x,我正在编写一个简单的ejb应用程序。部署成功,但当我尝试访问接口中定义的方法时,会引发以下异常: org.jboss.ejb.client.EJBClient <clinit> INFO: JBoss EJB Client version 1.0.5.Final Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:,mod

我正在编写一个简单的ejb应用程序。部署成功,但当我尝试访问接口中定义的方法时,会引发以下异常:

org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 1.0.5.Final
Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorldSessionBean,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@2cc5c76c
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    at com.sun.proxy.$Proxy0.sayHello(Unknown Source)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:16)
界面:

package com.ibytecode.business;
import javax.ejb.Remote;

@Remote
public interface HelloWorld {
    public String sayHello();
}
我还有一个类,用于建立服务器上下文,并由客户机用于rmi

import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class ClientUtility {

    private static Context initialContext;

    private static final String PKG_INTERFACES = "org.jboss.ejb.client.naming";

    public static Context getInitialContext() throws NamingException {
        if (initialContext == null) {
            Properties properties = new Properties();
            properties.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);
            // This should fix JNDI issues
            properties.put("jboss.naming.client.ejb.context", true);
            initialContext = new InitialContext(properties);
        }
        return initialContext;
    }
}
访问bean的客户端是:

package com.ibytecode.client;

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

import com.ibytecode.business.HelloWorld;
import com.ibytecode.businesslogic.HelloWorldBean;
import com.ibytecode.clientutility.ClientUtility;



public class EJBApplicationClient {

    public static void main(String[] args) {
        HelloWorld bean = doLookup();
        System.out.println(bean.sayHello()); // 4. Call business logic
    }

    private static HelloWorld doLookup() {
        Context context = null;
        HelloWorld bean = null;
        try {
            // 1. Obtaining Context
            context = ClientUtility.getInitialContext();
            // 2. Generate JNDI Lookup name
            String lookupName = getLookupName();
            // 3. Lookup and cast
            bean = (HelloWorld) context.lookup(lookupName);

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

    private static String getLookupName() {
/*
The app name is the EAR name of the deployed EJB without .ear suffix.
Since we haven't deployed the application as a .ear,
the app name for us will be an empty string
*/
        String appName = "";

        /* The module name is the JAR name of the deployed EJB
        without the .jar suffix.
        */
        String moduleName = "HelloWorldSessionBean";

/*AS7 allows each deployment to have an (optional) distinct name.
This can be an empty string if distinct name is not specified.
*/
        String distinctName = "";

        // The EJB bean implementation class name
        String beanName = HelloWorldBean.class.getSimpleName();

        // Fully qualified remote interface name
        final String interfaceName = HelloWorld.class.getName();

        // Create a look up string name
        String name = "ejb:" + appName + "/" + moduleName + "/" +
            distinctName    + "/" + beanName + "!" + interfaceName;

        System.out.println("Lookup name is: " + name);
        return name;
    }
}
我的jboss-ejb-client.properties是:

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.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
部署时的服务器日志如下所示:

package com.ibytecode.businesslogic;

import com.ibytecode.business.HelloWorld;

import javax.ejb.Stateful;

@Stateful
public class HelloWorldBean implements HelloWorld {
    public HelloWorldBean() {
    }

    public String sayHello() {
        return "Hello World !!!";
    }
}
15:18:51,487 INFO  [org.jboss.modules] JBoss Modules version 1.1.1.GA
15:18:51,872 INFO  [org.jboss.msc] JBoss MSC version 1.0.2.GA
15:18:51,973 INFO  [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting
15:18:53,282 INFO  [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)
15:18:53,282 INFO  [org.xnio] XNIO Version 3.0.3.GA
15:18:53,299 INFO  [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
15:18:53,311 INFO  [org.jboss.remoting] JBoss Remoting version 3.2.3.GA
15:18:53,347 INFO  [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
15:18:53,352 INFO  [org.jboss.as.configadmin] (ServerService Thread Pool -- 26) JBAS016200: Activating ConfigAdmin Subsystem
15:18:53,381 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 38) JBAS011800: Activating Naming Subsystem
15:18:53,393 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) JBAS010280: Activating Infinispan subsystem.
15:18:53,406 INFO  [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011940: Activating OSGi Subsystem
15:18:53,407 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 44) JBAS013101: Activating Security Subsystem
15:18:53,415 INFO  [org.jboss.as.connector] (MSC service thread 1-5) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)
15:18:53,446 INFO  [org.jboss.as.naming] (MSC service thread 1-6) JBAS011802: Starting Naming Service
15:18:53,448 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-6) JBAS015400: Bound mail session [java:jboss/mail/Default]
15:18:53,450 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
15:18:53,522 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
15:18:53,529 INFO  [org.jboss.as.security] (MSC service thread 1-6) JBAS013100: Current PicketBox version=4.0.7.Final
15:18:53,801 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-3) Starting Coyote HTTP/1.1 on http-localhost-127.0.0.1-8080
15:18:53,826 INFO  [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-4) JBoss Web Services - Stack CXF Server 4.0.2.GA
15:18:54,198 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-7) JBAS015012: Started FileSystemDeploymentService for directory C:\Utils\jboss-as-7.1.1.Final\jboss-as-7.1.1.Final\standalone\deployments
15:18:54,201 INFO  [org.jboss.as.remoting] (MSC service thread 1-6) JBAS017100: Listening on localhost/127.0.0.1:4447
15:18:54,204 INFO  [org.jboss.as.remoting] (MSC service thread 1-2) JBAS017100: Listening on /127.0.0.1:9999
15:18:54,214 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found HelloWorldSessionBean.jar in deployment directory. To trigger deployment create a file called HelloWorldSessionBean.jar.dodeploy
15:18:54,355 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
15:18:54,394 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: Starting deployment of "HelloWorldSessionBean.jar"
15:18:54,584 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-6) JNDI bindings for session bean named HelloWorldBean in deployment unit deployment "HelloWorldSessionBean.jar" are as follows:

    java:global/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
    java:app/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
    java:module/HelloWorldBean!com.ibytecode.business.HelloWorld
    java:jboss/exported/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
    java:global/HelloWorldSessionBean/HelloWorldBean
    java:app/HelloWorldSessionBean/HelloWorldBean
    java:module/HelloWorldBean

15:18:54,763 INFO  [org.jboss.as] (MSC service thread 1-6) JBAS015951: Admin console listening on http://127.0.0.1:9990
15:18:54,763 INFO  [org.jboss.as] (MSC service thread 1-6) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 3757ms - Started 169 of 246 services (76 services are passive or on-demand)
15:18:54,830 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "HelloWorldSessionBean.jar"

我已经弄明白了。jboss-ejb-client.properties文件存在问题。在jboss中,默认情况下会启用as 7安全凭据,因此必须在.properties文件中指定。新文件如下:

JBossEJB客户端。属性:

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.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

remote.connection.default.username=myUser
remote.connection.default.password=myPass
要添加新用户,请执行以下操作:

%JBOSS_HOME%\bin\add-user.bat (Win) 

$JBOSS_HOME/add-user.sh (*nix)
其中JBOSS_HOME是解压JBOSS的目录(假设使用的是二进制版本)。 此文件还必须放置在当前项目的类路径中:

请注意,将jboss-ejb-client.properties放置在项目根目录中可能会导致部署失败

为了在jboss7中成功部署应用程序,还需要在中创建扩展名为.dodeploy的(标记)文件

%JBOSS_HOME%\standalone\deployments\
标记文件必须具有以下命名结构:

ProjectName.jar.dodeploy
就我而言,它是:

HelloWorldSessionBean.jar.dodeploy
请注意,名为ProjectName.jar的目录(在我的示例中为HelloWorldSessionBean.jar)也必须存在于:

%JBOSS_HOME%\standalone\deployments\
此目录包含与bean和客户机相关的类文件

标记文件的类型以及示例工作流如下所示:

The marker files always have the same name as the deployment content to which
they relate, but with an additional file suffix appended. For example, the
marker file to indicate the example.war file should be deployed is named
example.war.dodeploy. Different marker file suffixes have different meanings.

The relevant marker file types are:

.dodeploy      -- Placed by the user to indicate that the given content should
                  be deployed into the runtime (or redeployed if already
                  deployed in the runtime.)

.skipdeploy    -- Disables auto-deploy of the content for as long as the file
                  is present. Most useful for allowing updates to exploded
                  content without having the scanner initiate redeploy in the
                  middle of the update. Can be used with zipped content as
                  well, although the scanner will detect in-progress changes
                  to zipped content and wait until changes are complete.

.isdeploying   -- Placed by the deployment scanner service to indicate that it
                  has noticed a .dodeploy file or new or updated auto-deploy
                  mode content and is in the process of deploying the content.
                  This marker file will be deleted when the deployment process
                  completes.

.deployed      -- Placed by the deployment scanner service to indicate that the
                  given content has been deployed into the runtime. If an end
                  user deletes this file, the content will be undeployed.

.failed        -- Placed by the deployment scanner service to indicate that the
                  given content failed to deploy into the runtime. The content
                  of the file will include some information about the cause of
                  the failure. Note that with auto-deploy mode, removing this
                  file will make the deployment eligible for deployment again.

.isundeploying -- Placed by the deployment scanner service to indicate that it
                  has noticed a .deployed file has been deleted and the
                  content is being undeployed. This marker file will be deleted
                  when the undeployment process completes.

.undeployed    -- Placed by the deployment scanner service to indicate that the
                  given content has been undeployed from the runtime. If an end
                  user deletes this file, it has no impact.

.pending       -- Placed by the deployment scanner service to indicate that it
                  has noticed the need to deploy content but has not yet
                  instructed the server to deploy it. This file is created if
                  the scanner detects that some auto-deploy content is still in
                  the process of being copied or if there is some problem that
                  prevents auto-deployment. The scanner will not instruct the
                  server to deploy or undeploy any content (not just the
                  directly affected content) as long as this condition holds.

Basic workflows:

All examples assume variable $AS points to the root of the JBoss AS distribution.
Windows users: the examples below use Unix shell commands; see the "Windows
Notes" below.

A) Add new zipped content and deploy it:

1. cp target/example.war $AS/standalone/deployments
2. (Manual mode only) touch $AS/standalone/deployments/example.war.dodeploy

B) Add new unzipped content and deploy it:

1. cp -r target/example.war/ $AS/standalone/deployments
2. (Manual mode only) touch $AS/standalone/deployments/example.war.dodeploy

C) Undeploy currently deployed content:

1. rm $AS/standalone/deployments/example.war.deployed

D) Auto-deploy mode only: Undeploy currently deployed content:

1. rm $AS/standalone/deployments/example.war

Note that this approach is not recommended with unzipped content as the server
maintains no other copy of unzipped content and deleting it without first
triggering an undeploy temporarily results in a live application with
potentially critical resources no longer available. For unzipped content use
the 'rm $AS/standalone/deployments/example.war.deployed' approach.

E) Replace currently deployed zipped content with a new version and deploy it:

1. cp target/example.war/ $AS/standalone/deployments
2. (Manual mode only) touch $AS/standalone/deployments/example.war.dodeploy

F) Manual mode only: Replace currently deployed unzipped content with a new
   version and deploy it:

1. rm $AS/standalone/deployments/example.war.deployed
2. wait for $AS/standalone/deployments/example.war.undeployed file to appear
3. cp -r target/example.war/ $AS/standalone/deployments
4. touch $AS/standalone/deployments/example.war.dodeploy

G) Auto-deploy mode only: Replace currently deployed unzipped content with a
   new version and deploy it:

1. touch $AS/standalone/deployments/example.war.skipdeploy
2. cp -r target/example.war/ $AS/standalone/deployments
3. rm $AS/standalone/deployments/example.war.skipdeploy

H) Manual mode only: Live replace portions of currently deployed unzipped
   content without redeploying:

1. cp -r target/example.war/foo.html $AS/standalone/deployments/example.war

I) Auto-deploy mode only: Live replace portions of currently deployed unzipped
   content without redeploying:

1. touch $AS/standalone/deployments/example.war.skipdeploy
2. cp -r target/example.war/foo.html $AS/standalone/deployments/example.war

J) Manual or auto-deploy mode: Redeploy currently deployed content (i.e. bounce
   it with no content change):

1. touch $AS/standalone/deployments/example.war.dodeploy

K) Auto-deploy mode only: Redeploy currently deployed content (i.e. bounce
   it with no content change):

1. touch $AS/standalone/deployments/example.war


Windows Notes:

The above examples use Unix shell commands. Windows equivalents are:

cp src dest --> xcopy /y src dest
cp -r src dest --> xcopy /e /s /y src dest
rm afile --> del afile
touch afile --> echo>> afile

Note that the behavior of 'touch' and 'echo' are different but the
differences are not relevant to the usages in the examples above.

我挣扎了将近半天,终于修好了。最后的解决办法

  • 您必须将jboss-ejb-client.properties放在to SRC文件夹中
  • 请更改Client.java类中的
    getLookupName()
    方法,如下所述
  • 这对我很有用

    private static String getLookupName() {
        /*
         * The app name is the EAR name of the deployed EJB without .ear suffix.
         * Since we haven't deployed the application as a .ear, the app name for
         * us will be an empty string
         */
        String appName = "EJBDemoEAR";
    
        /*
         * The module name is the JAR name of the deployed EJB without the .jar
         * suffix.
         */
        String moduleName = "EJBDemo";
    
        /*
         * AS7 allows each deployment to have an (optional) distinct name. This
         * can be an empty string if distinct name is not specified.
         */
        String distinctName = "";
    
        // The EJB bean implementation class name
        String beanName = "HelloWorldBean";
    
        // Fully qualified remote interface name
        final String interfaceName = "com.test.ejb.HelloWorld";
    
        // Create a look up string name
        String name = "ejb:" + appName + "/" + moduleName + distinctName
                + "/" + beanName + "!" + interfaceName;
    
        return name;
    }