我收到以下错误:
Severe: Exception while deploying the app [snel-transport-web] : Cannot resolve reference Local ejb-ref name=UserFacade,Local 3.x interface =null,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session
我用谷歌搜索了错误,我在Stack Overflow上得到了以下问题:
EJB Injection failure on deploy
Getting Cannot resolve reference Local ejb-ref not implementing parent interface
我认为它与我的注释@remote
和@LocalBean
有关。
以下是我目前的代码:
AbstractFacade.java:
@Remote
public abstract class AbstractFacade<T> {
private Class<T> entityClass;
public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}
protected abstract EntityManager getEntityManager();
public void create(T entity) {
getEntityManager().persist(entity);
}
public void edit(T entity) {
getEntityManager().merge(entity);
}
public void remove(T entity) {
getEntityManager().remove(getEntityManager().merge(entity));
}
public T find(Object id) {
return getEntityManager().find(entityClass, id);
}
public List<T> findAll() {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
}
public List<T> findRange(int[] range) {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(entityClass));
javax.persistence.Query q = getEntityManager().createQuery(cq);
q.setMaxResults(range[1] - range[0] + 1);
q.setFirstResult(range[0]);
return q.getResultList();
}
public int count() {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
javax.persistence.criteria.Root<T> rt = cq.from(entityClass);
cq.select(getEntityManager().getCriteriaBuilder().count(rt));
javax.persistence.Query q = getEntityManager().createQuery(cq);
return ((Long) q.getSingleResult()).intValue();
}
}
UserFacade.java:
@Stateless
@LocalBean
public class UserFacade extends AbstractFacade<User> {
@PersistenceContext(unitName = "com.mycompany_snel-transport-ejb_ejb_1.0-SNAPSHOTPU")
private EntityManager em;
@Override
protected EntityManager getEntityManager() {
return em;
}
public UserFacade() {
super(User.class);
}
}
AuthCtrl.java:
@Path("/auth")
@ApplicationPath("/api")
public class AuthCtrl extends Application {
com.mycompany.UserFacade userFacade = lookupUserFacadeBean();
/**
*
* @return
*/
@GET
@Path("/user")
public String getHelloMsg() {
return "test";
}
/**
*
* @param message
* @return
*/
@POST
@Path("/register")
public String register(String message) {
// Register user
// userFacade.create(entity);
return "done registering";
}
private com.mycompany.UserFacade lookupUserFacadeBean() {
try {
Context c = new InitialContext();
return (com.mycompany.UserFacade) c.lookup("java:global/com.mycompany_snel-transport-ear_ear_1.0-SNAPSHOT/com.mycompany_snel-transport-ejb_ejb_1.0-SNAPSHOT/UserFacade!com.mycompany.UserFacade");
} catch (NamingException ne) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
}
}
}
答案 0 :(得分:1)
你有LocalBean
实现Remote
接口(在这种情况下扩展了类,但它仍然适用)。尝试将Remote
更改为Local
或LocalBean
更改为RemoteBean
。如果这对于完全从抽象类中删除注释没有帮助。
答案 1 :(得分:0)
尝试重命名Bean,如果收到相同的错误消息(带有旧的Bean名称),则可能是从xml配置文件中引用了该Bean。我收到了与您相同的错误消息,问题是netbeans以某种方式在web.xml文件中生成了对我的bean的引用。