2013-02-08 42 views
0

對於所有這些東西來說我還是個新手。我嘗試通過GlassFish啓動web服務。當我嘗試構建這個項目時,我得到一個錯誤。GlassFish例外

ant -f /home/philipp/NetBeansProjects/sks3 -DforceRedeploy=false -Ddirectory.deployment.supported=true -Dnb.wait.for.caches=true run 
init: 
deps-module-jar: 
deps-ear-jar: 
deps-jar: 
check-rest-config-props: 
generate-rest-config: 
library-inclusion-in-archive: 
library-inclusion-in-manifest: 
compile: 
compile-jsps: 
In-place deployment at /home/philipp/NetBeansProjects/sks3/build/web 
Initializing... 
deploy?DEFAULT=/home/philipp/NetBeansProjects/sks3/build/web&name=sks3&contextroot=/sks3&force=true failed on GlassFish Server 3.1.2 
Error occurred during deployment: Exception while deploying the app [sks3] : Invalid TYPE-level @EJB with name() = [] and beanInterface = [class java.lang.Object] in class Webservice.MeasurementResources. Each TYPE-level @EJB must specify both name() and beanInterface().at [email protected] Please see server.log for more details. 
/home/philipp/NetBeansProjects/sks3/nbproject/build-impl.xml:1028: The module has not been deployed. 
See the server log for details. 
BUILD FAILED (total time: 6 seconds) 

我沒有一個線索是怎麼回事錯誤的,但根據它必須在文件MeasurementResurces.java消息...

/* 
* To change this template, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package Webservice; 

import Exception.DALException; 
import dal.MeasurementDao; 
import javax.ejb.EJB; 
import javax.ejb.Stateless; 
import javax.inject.Inject; 
import javax.inject.Named; 
import javax.ws.rs.Path; 
import repo.Measurement; 

/** 
* 
* @author philipp 
*/ 
//@Stateless 
//@inject 
@EJB 
//@LocalBean 
@Named 
@Path("Measurement") 
public class MeasurementResources { 
    @Inject 
    MeasurementDao mDao; 
    public void add(Measurement arg) throws DALException{ 
     mDao.save(arg); 
    } 
/* public void getAll(Measurement arg) throws DALException{ 
     mDao.getAll(); 
    } 
    */ 
} 

有人至少有一個暗示什麼問題?

+0

你看服務器日誌,因爲它暗示? – Preston 2013-02-08 20:55:26

回答

1

您正在使用Type-Level EJB,但未聲明namebeanInterface

/** 
* 
* @author philipp 
*/ 
//@Stateless 
//@inject 
@EJB(name="MyEjb", beanInterface=RemoteEjb.class) 
//@LocalBean 
@Named 
@Path("Measurement") 
public class MeasurementResources { 
    @Inject 
    MeasurementDao mDao; 
    public void add(Measurement arg) throws DALException{ 
     mDao.save(arg); 
    } 
} 

@Remote 
public interface RemoteEjb { 
    public void doSomething(); 
} 

@Stateless 
public class MyEjb implements RemoteEjb { 
    ... 
} 

name是您嘗試注入的EJB的名稱。 beanInterface是本地或遠程界面。這不是真正的注射。這是一種使用註釋來替代部署描述符ejb-ref元素的方法。您應該使用JNDI查找來注入ejb。

我不知道你有什麼做的,但注入一個EJB的常見方式如下:

@Named 
@Path("Measurement") 
public class MeasurementResources { 
    @EJB 
    private MyEjb myejb; 

    @Inject 
    MeasurementDao mDao; 
    public void add(Measurement arg) throws DALException{ 
     mDao.save(arg); 
    } 

    ... 
}