1

我正在使用 netbeans 7.2.1 和 glassfish 3.1 开发一个 maven ear 项目。我想在 JSF 托管控制器中使用无状态 EJB 外观,并且由于 EJB 注入不起作用,我正在尝试进行 JNDI 查找。所以我复制了 glassfish logging 打印的以下便携式 JNDI 名称:

信息:EJB5181:EJB AirportFacade 的可移植 JNDI 名称:[java:global/com.procc_FLAMS-ear_ear_1.0-SNAPSHOT/FLAMS-web-1.0-SNAPSHOT/AirportFacade, java:global/com.procc_FLAMS-ear_ear_1.0-SNAPSHOT/ FLAMS-web-1.0-SNAPSHOT/AirportFacade!com.procc.dao.AirportFacadeLocal]

当我运行该项目时,它说查找失败!

错误信息:

SEVERE: javax.naming.NamingException: Lookup failed for 'java:global/FLAMS-ear-1.0-SNAPSHOT/FLAMS-ejb-1.0-SNAPSHOT/AirportFacade!com.procc.dao.AirportFacadeLocal' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: FLAMS-ear-1.0-SNAPSHOT]

我不知道为什么?

以下是 pom 标头:

EAR 模块:

<modelVersion>4.0.0</modelVersion>   <parent>
    <artifactId>FLAMS</artifactId>
    <groupId>com.procc</groupId>
    <version>1.0-SNAPSHOT</version>   </parent>

  <groupId>com.procc</groupId>   <artifactId>FLAMS-ear</artifactId>   <version>1.0-SNAPSHOT</version>   <packaging>ear</packaging>

  <name>FLAMS-ear</name>

EJB 模块:

<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>FLAMS</artifactId>
<groupId>com.procc</groupId>
<version>1.0-SNAPSHOT</version>   </parent>

<groupId>com.procc</groupId>
<artifactId>FLAMS-ejb</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ejb</packaging>

<name>FLAMS-ejb</name>

最后是无状态 EJB:

@Stateless 公共类 AirportFacade 扩展 AbstractFacade 实现 AirportFacadeLocal { @PersistenceContext(unitName = "flams_pu") private EntityManager em;

@Override
protected EntityManager getEntityManager() {
    return em;
}

public AirportFacade() {
    super(Airport.class);
} }

JSF bean 中的 JNDI 查找:

@ManagedBean(name="airportController") @ViewScoped 公共类 AirportController 扩展 AbstractController 实现 Serializable {

private transient AirportFacade ejbFacade;

public AirportController() {
    super(Airport.class);
}

@PostConstruct public void init() {

    super.setFacade(ejbFacade);
    if(ejbFacade==null){
        try {
            Context ctx = new InitialContext();
            ejbFacade = (AirportFacade)ctx.lookup("java:global/com.procc_FLAMS-ear_ear_1.0-SNAPSHOT/FLAMS-web-1.0-SNAPSHOT/AirportFacade!com.procc.dao.AirportFacadeLocal");
        } catch (NamingException ex) {
            Logger.getLogger(AirportController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
4

0 回答 0