简体   繁体   中英

Wildfly @Remote interface JNDI lookup between 2 ears in the same server

I am migrating Java EE 6 application from glassfish 3.1.1.2 to WildFly 18.

There are two ears deployed to server:

+ CoreEar
    + CoreEjb.jar
+ AppEar
    + AppEjb.jar
    + somewar1.war
    + somewar2.war

In CoreEjbs I've got a remote interface:

@Remote
public interface ExampleInterface {
    // methods
}

And implementing bean:

@Stateless
@LocalBean
public class Example implements ExampleInterface {
    // methods implementation
}

And it is used in AppEjb:

public class SomeManager {
    @EJB
    ExampleInterface injectedBean;
}

This code was deploying and working fine on glassfish. But it doesn't work on WildFly 18.

CoreEar deploys fine and in logs I can find information about JNDI bindings for session bean named 'Example':

[org.jboss.as.ejb3.deployment] (MSC service thread 1-2) WFLYEJB0473: JNDI bindings for session bean named 'Example' in deployment unit 'subdeployment "CoreEjb.jar" of deployment "CoreEar.ear"' are as follows:
    java:global/CoreEar/CoreEjb/Example!com.company.example.ExampleInterface
    java:app/CoreEjb/Example!com.company.core.ExampleInterface
    java:module/Example!com.company.core.ExampleInterface
    java:jboss/exported/CoreEar/CoreEjb/Example!com.company.core.ExampleInterface
    ejb:CoreEar/CoreEjb/Example!com.company.core.ExampleInterface
    java:global/CoreEar/CoreEjb/Example!com.company.core.Example
    java:app/CoreEjb/Example!com.company.core.Example
    java:module/Example!com.company.core.Example
    ejb:CoreEar/CoreEjb/Example!com.company.core.Example

But then when I deploy AppEar I get exceptions:

13:45:38,344 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC000001: Failed to start service jboss.deployment.subunit."AppEar.ear"."AppEjb.jar".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.subunit."AppEar.ear"."AppEjb.jar".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of subdeployment "AppEjb.jar" of deployment "AppEar.ear"
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:183)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
        at org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
        at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
        at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1363)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEE0052: Failed to install component SomeManager
        at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:109)
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:176)
        ... 8 more
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0406: No EJB found with interface of type 'com.company.core.ExampleInterface' for binding com.company.managers.SomeManager/injectedBean
        at org.jboss.as.ejb3.deployment.processors.EjbInjectionSource.getResourceValue(EjbInjectionSource.java:90)
        at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.processBindings(ComponentInstallProcessor.java:261)
        at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.access$000(ComponentInstallProcessor.java:80)
        at org.jboss.as.ee.component.deployers.ComponentInstallProcessor$1.handle(ComponentInstallProcessor.java:213)
        at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:54)
        at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deployComponent(ComponentInstallProcessor.java:216)
        at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:101)
        ... 9 more

I am able to solve this exception when I add lookup string to @EJB annotation

@EJB(lookup = "java:app/CoreEjbs/Example!com.company.core.ExampleInterface")
ExampleInterface injectedBean;

I don't know if it will deploy because there are exceptions for look-up of other interfaces in CoreEjbs.

The problem is that ExampleInterface is injected in many more beans and there are interfaces other than ExampleInterface in CoreEjbs that are also injected in many beans.

Declaring lookup in every place where a remote @EJB is injected is a lot of work and would make it hard to change implementations later etc.

Is there any way to declare globally JNDI look-up name for every @EJB ExampleInterface occurence?

I've tried somethings with ejb-jar.xml and jboss-ejb3.xml but none of it worked.

We solve this problem by creating producer and then just do simple injection. Is allow place jndi path in one place.

@Remote
public interface ExampleRemote extends Example {
}

public class ExampleProducer {
    @Produces
    @EJB(lookup = "java:global/example/ejb/ExampleEJB!com.example.ExampleRemote")
    private static ExampleRemote exampleRemote;

}

@Inject
private Example example;

The problem is that you have 2 EARs deployed and their order of deployment is non-deterministic. When your application requests a dependency ejb, it might not have been deployed, hence the failure.

You can require some applications to be deployed before some other applications via jboss-all.xml . For instance, package the following jboss-all.xml in appEar:

<jboss umlns="urn:jboss:1.0">
        <jboss-deployment-dependencies xmlns="urn:jboss:deployment-dependencies:1.0">
             <dependency name="coreEar.ear" />
        </jboss-deployment-dependencies>
</jboss>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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