2016-11-09 34 views
1

我使用eclipse霓虹燈。
我創建瞭如下代碼簡單的EJB項目:「類型」不能解析到一個類型,而在jsp中使用ejb

package com.clientManager; 

import javax.ejb.LocalBean; 
import javax.ejb.Stateless; 

/** 
* Session Bean implementation class ClientManager 
*/ 
@Stateless 
@LocalBean 
public class ClientManager { 

    /** 
    * Default constructor. 
    */ 
    public ClientManager() { 
     // TODO Auto-generated constructor stub 
    } 

    public String test() { 
     return "test"; 
    } 
} 

它自動創建並駐留在的ejbModule文件夾中。
它使用EJB 3.2和WildFly服務器上成功部署:

11:25:50,360 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0028: Stopped deployment Neoflex.jar (runtime-name: Neoflex.jar) in 9ms 
11:25:50,370 WARN [org.jboss.as.controller] (DeploymentScanner-threads - 2) WFLYCTL0357: Notification of type deployment-undeployed is not described for the resource at the address [] 
11:25:50,370 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0009: Undeployed "Neoflex.jar" (runtime-name: "Neoflex.jar") 
11:25:55,380 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found Neoflex.jar in deployment directory. To trigger deployment create a file called Neoflex.jar.dodeploy 
11:25:55,380 INFO [org.jboss.as.server.deployment] (MSC service thread 1-7) WFLYSRV0027: Starting deployment of "Neoflex.jar" (runtime-name: "Neoflex.jar") 
11:25:55,400 INFO [org.jboss.weld.deployer] (MSC service thread 1-6) WFLYWELD0003: Processing weld deployment Neoflex.jar 
11:25:55,400 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-6) WFLYEJB0473: JNDI bindings for session bean named 'ClientManager' in deployment unit 'deployment "Neoflex.jar"' are as follows: 

    java:global/Neoflex/ClientManager!com.clientManager.ClientManager 
    java:app/Neoflex/ClientManager!com.clientManager.ClientManager 
    java:module/ClientManager!com.clientManager.ClientManager 
    java:global/Neoflex/ClientManager 
    java:app/Neoflex/ClientManager 
    java:module/ClientManager 

11:25:55,523 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0010: Deployed "Neoflex.jar" (runtime-name : "Neoflex.jar") 

現在我創建DynamicWebProject爲此將使用EJB JSP頁面:

<%@page import="com.clientManager.*"%> 
<% 
    ClientManager c = new ClientManager(); 
%> 
<%= c.test() %> 

我在JSP項目中的EJB的構建路徑配置項目(!)
請看截圖。

screenshot

當我發佈JSP和訪問頁面(main.jsp中),我有:

JBWEB004060: An error occurred at line: 3 in the jsp file: /main.jsp 
ClientManager cannot be resolved to a type 
1: <%@page import="com.clientManager.*"%> 
2: <% 
3: ClientManager c = new ClientManager(); 
4: %> 
5: <%= c.test() %> 

有什麼不對?

回答

1

你應該直接實例化EJB bean,而不是EJB容器管理的生命週期,獲取EJB bean句柄的正確方法是通過查找方法。

請確保您選擇正確的查找名稱,我隨機使用您的帖子中的一個 嘗試更改爲如下所示。

<% 
    ClientManager cm; 
    cm = (ClientManager) ctx.lookup("java:module/ClientManager"); 
%> 
+0

Thanx,但我解決了它通過創建「企業應用程序項目」 –

相關問題