Jboss AS 7 - 依赖注入

时间:2011-09-15 07:17:17

标签: dependency-injection ejb ejb-3.0 jboss7.x

我试图在Jboss AS 7中使用依赖注入,并且我遇到了很大的困难。

我已经设置了一个包含EJB jar和战争的EAR。

战争包含一个richfaces网络应用程序。

我试图将一个EJB从ejb jar注入到faces托管bean中,代码如下:

 public class UserController {

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

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

然而,当我部署jboss时,将错误放入控制台:

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)

请协助!

2 个答案:

答案 0 :(得分:1)

看起来问题可能是您的WAR没有定义EJB jar的依赖项。如果没有,最好为EJB jar文件定义WAR的META-INF / MANIFEST.MF的Class-Path条目。

您可能还想检查配置文件,并确保<ear-subdeployments-isolated />标记设置为false。

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

class loading in JBoss AS7还有一些不错的文档。

答案 1 :(得分:0)

首先,确保在战争中,你有 META-INF / MANIFEST.MF 文件,并且有 Class-Path:GoodByeJohnEJB-1.0-SNAPSHOT.jar < /强>,

然后在您的UserController类中,尝试删除mappedName,只需添加EJB注释。

或者,您可以使用:

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