[jboss-user] [EJB 3.0] - Re: Why is injection not working in AS 4.0 and 4.2 (servlets

jobor do-not-reply at jboss.com
Fri Jun 22 02:23:52 EDT 2007


Hello,

I wanted to use EJB3 with JSF1.2 and injection. For this combination you have to do a little bit more work in JBoss-4.2.0.GA. This is how injection worked for me:

The ejb jar and war file are deployed separate from each other in the same deploy diectory. So not in an EAR file! There is also no ejb-jar.xml in the EJB3 app.

The EJB3 bean:

  | @Stateless
  | @Local(NewsAgentLocal.class)
  | public class NewsAgentBean implements NewsAgent {
  | ...
  | }
  | 

The EJB3 local interface:

  | @Local
  | public interface NewsAgentLocal extends NewsAgent {
  | }
  | 

The JSF1.2 backing bean:

  | public class WelcomeHandler {
  | 
  |   @EJB(name="java:comp/env/ejb/NewsAgent") private NewsAgentLocal agent;
  | 
  |   public DataModel getNewsModel() {
  |     NewsFilter f = new NewsFilter();
  |     Integer year = new Integer(Calendar.getInstance().get(Calendar.YEAR));
  |     f.setYear(year.shortValue());
  |     newsModel.setWrappedData(agent.getNewsItems(f));
  |     return newsModel;
  |   }
  | ...
  | }
  | 

The web.xml:

  |   <ejb-local-ref>
  |     <ejb-ref-name>ejb/NewsAgent</ejb-ref-name>
  |     <ejb-ref-type>Session</ejb-ref-type>
  |     <local-home></local-home>
  |     <local>nl.borsoft.hd.news.NewsAgentLocal</local>
  |   </ejb-local-ref>
  | 

The jboss-web.xml:

  |   <ejb-local-ref>
  |     <ejb-ref-name>ejb/NewsAgent</ejb-ref-name>
  |     <local-jndi-name>NewsAgentBean/local</local-jndi-name>
  |   </ejb-local-ref>
  | 

For all XML descriptors I do use the EE5 document type declarations.
You can find them in jboss-4.2.0.GA\docs\dtd and jboss-4.2.0.GA\docs\schema.

With regards,
Johan Borchers


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4056735#4056735

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4056735



More information about the jboss-user mailing list