我正在使用EJB3.1和Glassfish 3.1在NetBeans 7中进行开发。 我试图从WAR中的POJO引用JAR中的会话Bean的本地接口。 当我部署到Glassfish时,我收到:
SEVERE: Unresolved <ejb-link>: TaskTool-ejb#ContextFacade
SEVERE: Exception while deploying the app [com.oracle.eas_TaskTool-ear_ear_1.0-SNAPSHOT]
SEVERE: Error: Unresolved <ejb-link>: TaskTool-ejb#ContextFacade
我使用NetBeans帮助程序生成引用会话Bean的本地接口的代码,并为我生成了web.xml中的<ejb-local-ref>
部分。
@Local
public interface ContextFacadeLocal {
void create(Context context);
void edit(Context context);
void remove(Context context);
Context find(Object id);
List<Context> findAll();
List<Context> findRange(int[] range);
int count();
List<Context> findRootContexts();
}
@Stateless
public class ContextFacade extends AbstractFacade<Context> implements ContextFacadeLocal {
@PersistenceContext(unitName = "TaskToolPU")
private EntityManager em;
protected EntityManager getEntityManager() {
return em;
}
public ContextFacade() {
super(Context.class);
}
@Override
public List<Context> findRootContexts() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Context> query = builder.createQuery(Context.class);
Root<Context> c = query.from(Context.class);
query.select(c).where(builder.isNull(c.get("parent")));
query.orderBy(builder.asc(c.get("id")));
TypedQuery<Context> q = em.createQuery(query);
return q.getResultList();
}
}
@FacesConverter(value = "contextConverter")
public class contextConverter implements Converter {
ContextFacadeLocal contextFacade = lookupContextFacadeLocal();
@Override
public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
return contextFacade.find(string);
}
@Override
public String getAsString(FacesContext fc, UIComponent uic, Object o) {ntityManager() {
return em;
}
public ContextFacade() {
super(Context.class);
}
@Override
public List<Context> findRootContexts() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Context> query = builder.createQuery(Context.class);
Root<Context> c = query.from(Context.class);
query.select(c).where(builder.isNull(c.get("parent")));
query.orderBy(builder.asc(c.get("id")));
TypedQuery<Context> q = em.createQuery(query);
return q.getResultList();
}
}
@FacesConverter(value = "contextConverter")
public class contextConverter implements Converter {
ContextFacadeLocal contextFacade = lookupContextFacadeLocal();
@Override
public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
return contextFacade.find(string);
}
@Override
public String getAsString(FacesContext fc, UIComponent uic, Object o) {
return ((Context) o).getId().toString();
}
private ContextFacadeLocal lookupContextFacadeLocal() {
try {
javax.naming.Context c = new InitialContext();
//return (ContextFacadeLocal) c.lookup("java:global/com.oracle.eas_TaskTool-ear_ear_1.0-SNAPSHOT/com.oracle.eas_TaskTool-ejb_ejb_1.0-SNAPSHOT/ContextFacade!com.oracle.eas.ejbs.ContextFacadeLocal");
return (ContextFacadeLocal) c.lookup("java:comp/env/TaskTool-ejb#ContextFacade");
} catch (NamingException ne) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<ejb-local-ref>
<ejb-ref-name>ContextFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>com.oracle.eas.ejbs.ContextFacadeLocal</local>
<ejb-link>TaskTool-ejb#ContextFacade</ejb-link>
</ejb-local-ref>
</web-app>
更新
为清楚起见:
我根本没有ejb-jar.xml。
使用<ejb-link>TaskTool-ejb/ContextFacade</ejb-link>
或<ejb-link>com.oracle.eas_TaskTool-ejb_ejb_1.0-SNAPSHOT/ContextFacade</ejb-link>
工作。
请参阅下面的bkail答案以获取解释。非常感谢!
答案 0 :(得分:7)
在尝试部署我的应用程序时遇到了同样的问题,NetBeans自己在我的web.xml中生成了这个代码。
检查你的web.xml,看看你是否看到了这个:
<ejb-local-ref>
<ejb-ref-name>appName</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<ejb-link>AppName#SomeClass</ejb-link>
</ejb-local-ref>
如果是这样,只需将其删除,就应该在之后进行部署。
答案 1 :(得分:2)
EJB模块的名称是什么?除非jar文件按字面意思命名为“TaskTool-ejb.jar”,否则你需要使用:
<ejb-link>TaskTool-ejb.jar#ContextFacade</ejb-link>
或:
<ejb-link>TaskTool-ejb/ContextFacade</ejb-link>
后者假设您没有覆盖ejb-jar.xml中的module-name。
更新:根据您自己的评论,您可能需要使用“com.oracle.eas_TaskTool-ejb_ejb_1.0-SNAPSHOT.jar#ContextFacade”或“com.oracle.eas_TaskTool-ejb_ejb_1.0-SNAPSHOT / ContextFacade”。
答案 2 :(得分:0)
我遇到了同样的问题。来自Glassfish Log的片段:
SEVERE: Exception while deploying the app [.....] : Error: Unresolved <ejb-link>: #NotifyMe
在Web服务中使用注释时(强烈建议使用注释)从sun-web.xml中删除所有触及Web服务的行。
即。在我的sun-web.xml中只有基本信息:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd">
<sun-web-app error-url="">
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</sun-web-app>
正如您所看到的,没有任何具体的应用程序。
答案 3 :(得分:0)
似乎TomEE不使用EAR&gt; EJB / WAR类加载器,它们在单战中处理,'MyEjbJar#MyEJB'不能用作ejb-link目标,我们必须改变
<ejb-link>MyEjb.jar#MyEJB</ejb-link>
>在/WEB-INF/web.xml中
<ejb-link>MyEJB</ejb-link>
代替。