Wildfly 10 EJB-Project injection EJB in separat JSF-Application
rkloeber Dec 10, 2016 7:46 AMHello,
i have a problem while injection EJB's in a JSF 2.2 webapp.
Project-Structure :
EAR-Project:
- project-api.jar (only interfaces)
- project-impl.jar (remote ejb's which implements the interfaces of project-api.jar
ex.:
project-api.jar
public interface MyRemoteBean { public void test(); }
project-impl.jar
@Remote(MyRemoteBean.class) @Stateless public class MyRemoteBeanImpl implements MyRemoteBean { @Override public void test(){ ... } }
Output of wildfly at deploy-time:
java:global/myproject-ear-1.0-SNAPSHOT/project-impl-1.0-SNAPSHOT/MyRemoteBeanImpl!com.example.projectapi.MyRemoteBean java:app/project-impl-1.0-SNAPSHOT/MyRemoteBeanImpl!com.example.projectapi.MyRemoteBean java:module/MyRemoteBeanImpl!com.example.projectapi.MyRemoteBean java:jboss/exported/myproject-ear-1.0-SNAPSHOT/project-impl-1.0-SNAPSHOT/MyRemoteBeanImpl!com.example.projectapi.MyRemoteBean java:global/testenterprise-ear-1.0-SNAPSHOT/project-impl-1.0-SNAPSHOT/MyRemoteBeanImpl java:app/project-impl-1.0-SNAPSHOT/MyRemoteBeanImpl java:module/MyRemoteBeanImpl
I have a JSF2.2 webapp (not in the EAR-Project !)
In the pom.xml of the webapp :
<dependency> <groupId>...</groupId> <artifactId>project-api</artifactId> <version>...</version> </dependency>
In this way i can code against the api with no knowing of implementation.
In a JSF-Bean :
@Named @ViewScoped @JBossLog public class MyViewController implements Serializable { private static final long serialVersionUID = 1L; @EJB private MyRemoteBean remoteBean; public String uiButtonPressed(){ log.info("bean initialized with: "+remoteBean; } }
remoteBean is always null
output of wildfly :
WFLYWELD0044: Error injecting resource into CDI managed bean. Can't find a resource named java:comp/env/com.example.webapp.MyViewController/remoteBean
I don't want the ejb project as an dependency of the webapp because if i have deployed the ear and later i deploy the webapp, all ejb's will be deployed twice.
My thinking, i develop an api (the project-api.jar), the implementation (myproject-impl.jar), both packed in an ear to provide the ejb's. This ear will be deployed to wildfly. Then i can code several webapps (or whatever) and only need the myproject-api.jar as a dependency.
I think many of provided libraries use this technic. faces-api, faces-impl for example.
Is there a way to do so i want?
Sorry for my english