Olga Pshenichnikova
Olga Pshenichnikova

Reputation: 1581

"type" cannot be resolved to a type, while using ejb in jsp

I use eclipse Neon.
I created simple EJB project with follow code:

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";
    }
}  

It created automatically and reside in ejbModule folder.
It uses EJB 3.2 and successfully deploying on WildFly server:

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")

Now I created DynamicWebProject for JSP page which will use the EJB:

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

I configured in Build Path of JSP project the EJB project (!)
Please see screenshot.

screenshot

When I publish JSP and access to the page (main.jsp), I have:

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() %>

What is wrong?

Upvotes: 1

Views: 969

Answers (1)

mhasan
mhasan

Reputation: 3709

You shouldn’t directly instantiate the EJB bean rather it lifecycle in managed by the EJB container, the right way of getting the EJB bean handle is via it's look up method.

Make sure you choose the correct look up name, I am using randomly the one from your post Try changing to something like below.

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

Upvotes: 1

Related Questions