简体   繁体   中英

@EJB not working in Servlet in external project WFLYEJB0406

Hi I have 3 projects: EAR, EJB and (dynamic) WEB. I'm using eclipse and wildfly 10.x. Here's what I've got in EJB project:

package q.w.e;

public interface Inter {
    public String s();
}

and

package q.w.e;
public class Ert implements Inter {
    @Override
    public String s() {
        return "hik";
    }
}

Here's what I have in dynamic web project:

package local.bb.lab.servlets;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import q.w.e.*;

public class Home extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @EJB
    Inter ert;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/home.jsp").forward(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}

All very simple. I connected the projects using EAR. The compiler sees the package and classes but I'm having this error:

WFLYEJB0406: No EJB found with interface of type 'q.w.e.Inter' for binding local.bb.lab.servlets.Home/ert

I have no idea why it remains there. This must be some configuration problem but I connected them just as it was shown in tutorials(took literaly the same steps).

In my opinion you need to know what the difference between @EJB and @Inject at first, you can check from this : link

Another thing is your code is not EJB that's why you cannot use @EJB annotation, you should use @Inject to dependency injection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM