Nic Willemse
Nic Willemse

Reputation: 101

Jboss AS 7 - Dependency Injection

Im attempting to make use of dependency injection in Jboss AS 7 and im having huge difficulties.

I have setup a EAR which contains both a EJB jar and a war.

The war contains a richfaces web app.

Im attempting to inject an EJB from the ejb jar into a faces managed bean with the code below :

 public class UserController {

    @EJB(mappedName="UserService")
    private UserFacadeService userService;

    public String getService(){
        if(userService == null){

however when i deploy jboss puts the error in the console :

rolled back with failure message {"Services with missing/unavailable dependencies" => ["jboss.deployment.subunit.\"GoodByeJohnEAR.ear\".\"GoodByeJohnWeb-1.0-SNAPSHOT.war\".component.\"managed-bean.za.co.gbj.UserController\".START missing [ jboss.naming.context.java.module.GoodByeJohnEAR.\"GoodByeJohnWeb-1.0-SNAPSHOT\".\"env/za.co.gbj.UserController/userService\" ]","jboss.deployment.subunit.\"GoodByeJohnEAR.ear\".\"GoodByeJohnWeb-1.0-SNAPSHOT.war\".jndiDependencyService missing [ jboss.naming.context.java.module.GoodByeJohnEAR.\"GoodByeJohnWeb-1.0-SNAPSHOT\".\"env/za.co.gbj.UserController/userService\" ]","jboss.naming.context.java.module.GoodByeJohnEAR.\"GoodByeJohnWeb-1.0-SNAPSHOT\".\"env/za.co.gbj.UserController/userService\".jboss.deployment.subunit.\"GoodByeJohnEAR.ear\".\"GoodByeJohnWeb-1.0-SNAPSHOT.war\".module.GoodByeJohnEAR.\"GoodByeJohnWeb-1.0-SNAPSHOT\".2 missing [ jboss.naming.context.java.module.GoodByeJohnEAR.\"GoodByeJohnWeb-1.0-SNAPSHOT\".env/UserService ]"]}
09:03:50,576 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) Starting deployment of "GoodByeJohnEAR.ear"
09:03:50,670 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) Starting deployment of "GoodByeJohnWeb-1.0-SNAPSHOT.war"
09:03:50,670 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) Starting deployment of "GoodByeJohnEJB-1.0-SNAPSHOT.jar"
09:03:51,367 WARN  [org.jboss.as.server.deployment.service-loader] (MSC service thread 1-2) Encountered invalid class name "com.sun.faces.vendor.Tomcat6InjectionProvider:org.apache.catalina.util.DefaultAnnotationProcessor" for service type "com.sun.faces.spi.injectionprovider"
09:03:51,367 WARN  [org.jboss.as.server.deployment.service-loader] (MSC service thread 1-2) Encountered invalid class name "com.sun.faces.vendor.Jetty6InjectionProvider:org.mortbay.jetty.plus.annotation.InjectionCollection" for service type "com.sun.faces.spi.injectionprovider"
09:03:51,375 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-8) JNDI bindings for session bean named UserFacadeBean in deployment unit subdeployment "GoodByeJohnEJB-1.0-SNAPSHOT.jar" of deployment "GoodByeJohnEAR.ear" are as follows:

    java:global/GoodByeJohnEAR/GoodByeJohnEJB-1.0-SNAPSHOT/UserFacadeBean!za.co.gbj.UserFacadeService
    java:app/GoodByeJohnEJB-1.0-SNAPSHOT/UserFacadeBean!za.co.gbj.UserFacadeService
    java:module/UserFacadeBean!za.co.gbj.UserFacadeService
    java:global/GoodByeJohnEAR/GoodByeJohnEJB-1.0-SNAPSHOT/UserFacadeBean
    java:app/GoodByeJohnEJB-1.0-SNAPSHOT/UserFacadeBean
    java:module/UserFacadeBean

09:03:51,406 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named UserFacadeBean in deployment unit subdeployment "GoodByeJohnWeb-1.0-SNAPSHOT.war" of deployment "GoodByeJohnEAR.ear" are as follows:

    java:global/GoodByeJohnEAR/GoodByeJohnWeb-1.0-SNAPSHOT/UserFacadeBean!za.co.gbj.UserFacadeService
    java:app/GoodByeJohnWeb-1.0-SNAPSHOT/UserFacadeBean!za.co.gbj.UserFacadeService
    java:module/UserFacadeBean!za.co.gbj.UserFacadeService
    java:global/GoodByeJohnEAR/GoodByeJohnWeb-1.0-SNAPSHOT/UserFacadeBean
    java:app/GoodByeJohnWeb-1.0-SNAPSHOT/UserFacadeBean
    java:module/UserFacadeBean

09:03:51,577 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 1) Service status report
   New missing/unsatisfied dependencies:
      service jboss.naming.context.java.module.GoodByeJohnEAR."GoodByeJohnWeb-1.0-SNAPSHOT".env/UserService (missing)
      service jboss.naming.context.java.module.GoodByeJohnEAR."GoodByeJohnWeb-1.0-SNAPSHOT"."env/za.co.gbj.UserController/userService" (missing)

Please assist!

Upvotes: 1

Views: 9238

Answers (2)

Xi CHEN
Xi CHEN

Reputation: 271

First, make sure in your war, you have the file META-INF/MANIFEST.MF, and there has the line Class-Path: GoodByeJohnEJB-1.0-SNAPSHOT.jar,

Then in your UserController class, try to remove the mappedName, just add the EJB annotation.

Or, you can use this :

InitialContext ic = new InitialContext();
UserFacadeService userService = (UserFacadeService )ic.lookup("java:global/GoodByeJohnEAR/GoodByeJohnEJB-1.0-SNAPSHOT/UserFacadeBean");

Upvotes: 0

James R. Perkins
James R. Perkins

Reputation: 17840

It looks like the issue might be that your WAR doesn't have a dependency for your EJB jar defined. It's best to define a Class-Path entry your WAR's META-INF/MANIFEST.MF for your EJB jar files if you have not.

You might also want to check your configuration file and make sure the <ear-subdeployments-isolated /> tag is set to false.

<subsystem xmlns="urn:jboss:domain:ee:1.0" >            
  <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
</subsystem>

There is also some decent documentation on class loading in JBoss AS7.

Upvotes: 1

Related Questions