Reputation: 1687
I'm having troubles invoking a remote EJB: first time I have to do that and I may be missing something. I've read many tutorials on the web, ad several answers here on SO
but I can't solve. That's what I've done so far.
My scenario is:
I've got two EAR
s deployed under Wildfly 10.0.0.Final
: server-ear
and client-ear
.
In server-ear
I've got server-api
and server-ejb
, the first being a simple Java module containing my EJB
s interfaces, the second being an EJB
module containing the implementations.
Those would be
@Remote
public interface DummyApi {
String getSomething();
}
and its implementation
@Stateless
@Remote(DummyApi.class)
public class DummyApiImpl implements DummyApi {
@Override
public String getSomething() {
return "SOMETHING";
}
}
In client-ear
I've got a simple EJB
module (client-ejb
) that defines a singleton EJB
which takes a reference to the DummyApi
interface:
@javax.ejb.Singleton
public class DummyClient {
private static final Logger log = LoggerFactory.getLogger(DummyClient.class);
private @EJB DummyApi dummyApi;
@PostConstruct
public void postConstruct() {
log.debug("***** " + dummyApi.getSomething() + "******");
}
}
In client-ejb
I also have placed the jboss-ejb-client.properties
file under src/main/resources
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port = 8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
As for the interdependencies of those modules (I'm using Maven):
server-ear
|---- server-api [compile]
|---- server-ejb [compile]
|-- server-api [provided]
and
client-ear
|---- server-api [compile]
|---- client-ejb [compile]
|-- server-api [provided]
Both EAR
s are dployed on the same local Wildfly 10.0.0.Final
(clean installation of the server, no customizations whatsoever).When I start the server, I have no problems in server-ear
.
client-ear
instead fails with the following exception
12:05:22,592 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.deployment.subunit."client-ear-0.0.1-SNAPSHOT.ear"."client-ejb-0.0.1-SNAPSHOT.jar".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.subunit."client-ear-0.0.1-SNAPSHOT.ear"."client-ejb-0.0.1-SNAPSHOT.jar".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of subdeployment "client-ejb-0.0.1-SNAPSHOT.jar" of deployment "client-ear-0.0.1-SNAPSHOT.ear"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:154)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEE0052: Failed to install component DummyClient
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:109)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:147)
... 5 more
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0406: No EJB found with interface of type 'com.server.api.DummyApi' for binding com.client.DummyClient/dummyApi
at org.jboss.as.ejb3.deployment.processors.EjbInjectionSource.getResourceValue(EjbInjectionSource.java:90)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.processBindings(ComponentInstallProcessor.java:263)
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:215)
at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:54)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deployComponent(ComponentInstallProcessor.java:218)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:101)
... 6 more
What am I missing or doing wrong?
Upvotes: 0
Views: 165
Reputation: 386
@EJB will work only if beans are on same package(.ear in your case).
You will need a lookup, using the java:app name that appears in server log at startup. Something like this:
DummyApi api = (DummyApi) context.lookup("/server-ear/server-ejb/DummyApiImpl!path.to.DummyApi")
To create context:
private static Context createContextWildfly(String provider) throws NamingException {
final Hashtable<String, String> properties = new Hashtable<>();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.put("jboss.naming.client.ejb.context", "true");
properties.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");
return new InitialContext(properties);
}
Using this you don't need jboss-ejb-client.properties
Upvotes: 1