@EJB injection fails, but JNDI lookup works in web service class in Glassfish

I have a @WebService class that introduces @EJB. EJB is packaged in a .jar file, which is located in the same .war file as the web service classes. @EJB injection always fails, but I can do a JNDI lookup in EJB. I tried to make EJB and its @Remote interface, but that didn't matter. Injection still doesn't work, and JNDI lookup still works.

I am using version 3.0 of web.xml. There is no ejb deployment descriptor in the ejb.jar file, but this should not matter in EJB 3.1.

Am I missing something or is this a bug in Glassfish?

Here is my code.

The EJB class and interface packaged in a .jar in a .war file:

//@Remote public interface ReportServiceI { public String testAlive(); } @Stateless //@Remote (ReportServiceI.class) public class ReportService implements ReportServiceI {...} 

Web Service Class:

 @WebService( targetNamespace = "http://www.reps.corp.com/services/reports/ReportService", portName="ReportPort", serviceName="ReportService", endpointInterface="com.corp.reps.reports.ws.server.ReportServiceWSI") public class ReportServiceWS implements ReportServiceWSI { public static Logger logger = Logger.getLogger(ReportServiceWS.class); // These all fail // @EJB // @EJB(beanInterface=ReportServiceI.class) // @EJB(lookup="java:global/repsreports/ReportService") ReportServiceI reportService; public String testAlive() { // this works try { InitialContext context = new InitialContext(); reportService = (ReportServiceI)context.lookup("java:global/repsreports/ReportService"); } catch (NamingException ex) { logger.error(ex); return "InitialContext.lookup() failed."; } 
+4
source share
2 answers

This is a bug in Glassfish (apparently in the web services stack).

+1
source

Peter,

No for both.

beans.xml is a CDI file and I use Glassfish as an injection container. I will try to make @WebService bean @stateless - this is the only thing I have not tried, but it is not necessary.

(This forum software will not allow me to add a comment below Piotr's.)

-one
source

Source: https://habr.com/ru/post/1398173/


All Articles