Embedding jBoss EJB in a managed JSF 2.0 bean running in tomcat web application

I searched for a while, and I cannot find a solution, the problem is this:

  • I have an EJB3 application deployed in jBoss 6.0 with ejb removed.
  • I have a web application (JSF 2.0) deployed in Tomcat 6.0.

I do not want to run the tomcat web application in jBoss, its application is running tomcat, and the architecture should remain the same.

I don’t want to search for EJB manually (I want to insert it), in other words, I don’t want to do it like this:

Properties properties = new Properties(); properties.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); properties.setProperty("java.naming.provider.url", "jnp://localhost:1099"); properties.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); Context c = new InitialContext(); MySB mySB = (MySB) c.lookup("MySB/remote"); 

I need to inject jBoss EJB into managed beans in a Tomcat application like

 @EJB(name="MySB/remote") protected MySB mySB; 

as if MySB/remote is in the local tomcat JNDI, but in fact it is being viewed from jBoss JNDI backstage.

perhaps?

+4
source share
1 answer

You can do this using CDI. Unfortunately, CDI support does not come with a standard servlet engine like Tomcat, so if you want to deploy a JSF application that uses CDI annotations, you need to get an implementation of the CDI specification. The reference implementation of JSR 299 is known as Weld . To install it you need:

1) put weld-servlet.jar in the WEB-INF\lib folder of your JSF application

2) add the following listener definition in web.xml :

 <listener> <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class> </listener> 

3) add an empty beans.xml file along with the web.xml and faces-config.xml file in the application’s WEB-INF folder:

 <?xml version="1.0" encoding="UTF-8"?> <beans 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/beans_1_0.xsd"> </beans> 

Finally, you need @Inject your EJB in managed beans.

Hope this helps.

+1
source

All Articles