{"id":882,"date":"2010-06-11T12:44:56","date_gmt":"2010-06-11T12:44:56","guid":{"rendered":"http:\/\/salientsoft.co.uk\/?p=882"},"modified":"2010-06-11T12:51:11","modified_gmt":"2010-06-11T12:51:11","slug":"further-notes-on-ejb-lookups","status":"publish","type":"post","link":"https:\/\/salientsoft.co.uk\/?p=882","title":{"rendered":"Further notes on EJB Lookups"},"content":{"rendered":"<p>Much of this has already been covered <strong><a title=\"http:\/\/salientsoft.co.uk\/?p=123\" href=\"http:\/\/salientsoft.co.uk\/?p=123\">here<\/a><\/strong>, but I am posting these somewhat raw notes from an earlier\u00a0investigative email as they include one or two links and points\u00a0not covered elsewhere. I don&#8217;t have the time or inclination at present to rework everything into an existing post :-<\/p>\n<p>\u00a0<\/p>\n<p>1\/ For local beans, you can just use defaults in @Stateless (in the bean) and in @EJB (in the referring code)<br \/>\nNote that when you do not use all the defaults, you must declare both the beaninterface and the name attributes<\/p>\n<p>@EJB(name=&#8221;ejb\/JPAGlassFishIce\/SimpleBean&#8221;, beanInterface=SimpleBeanLocal.class)<br \/>\nprivate SimpleBean simpleBean;<br \/>\n2\/ For remote beans, you can use e.g.<\/p>\n<p>@Stateless(mappedName=&#8221;ejb\/JPAGlassFishIceEJB\/SimpleBean&#8221;)<\/p>\n<p>Then<\/p>\n<p>@EJB(beanInterface=SimpleBeanRemote.class, mappedName=&#8221;ejb\/JPAGlassFishIceEJB\/SimpleBean&#8221;)<br \/>\nprivate SimpleBean simpleBean;<\/p>\n<p>Note \u2013 you must pass the class of the remote interface as above or it will not work, and you just get name not found exception.<\/p>\n<p>3\/ The above methods work for both access from one bean to another, and from a JSF managed bean to a remote (or local) bean<br \/>\nIt also works from any POJO called from e.g. a JSF manged bean.<br \/>\nNote that this ability is container specific \u2013 Glassfish does it, other containers may vary in what\/if\/how they support.<\/p>\n<p>4\/ If doing JNDI lookups yourself to a local bean (via context.lookup), you need to add &lt;ejb-local-ref&gt; to web.xml as follows :-<\/p>\n<p>\u00a0&lt;ejb-local-ref&gt;<br \/>\n\u00a0\u00a0\u00a0 &lt;ejb-ref-name&gt;ejb\/JPAGlassFishIce\/SimpleBean&lt;\/ejb-ref-name&gt;<br \/>\n\u00a0\u00a0\u00a0 &lt;ejb-ref-type&gt;Session&lt;\/ejb-ref-type&gt;<br \/>\n\u00a0\u00a0\u00a0 &lt;local-home&gt;&lt;\/local-home&gt;<br \/>\n\u00a0\u00a0\u00a0 &lt;local&gt;uk.co.salientsoft.jpaglassfishice.domain.SimpleBeanLocal&lt;\/local&gt;<br \/>\n&lt;\/ejb-local-ref&gt;<\/p>\n<p>This would be used if using e.g. Spring or a custom EL resolver\u00a0 to inject references into JSF managed beans (via JSF DI)<\/p>\n<p>Note that the JNDI name for the above local reference would be<br \/>\n&#8220;java:comp\/env\/ejb\/JPAGlassFishIce\/SimpleBean&#8221;<br \/>\ni.e. this is picking up from the &lt;ejb-ref-name&gt; above, and is prefixed java:comp\/env<br \/>\njava:comp\/env is a reference to the JNDI \u201cEnvironment\u201d service provider for Java EE<br \/>\nyou can also use this\u00a0 to look up environment variables etc.<br \/>\nsee here <a href=\"http:\/\/java.sun.com\/developer\/technicalArticles\/xml\/WebAppDev4\/\">http:\/\/java.sun.com\/developer\/technicalArticles\/xml\/WebAppDev4\/<\/a><\/p>\n<p>The &lt;ejb-local-ref&gt; stuff is done for you automatically if you use @EJB<\/p>\n<p>5\/ Note that JNDI names are container specific at present (fixed in java ee6)<br \/>\nSee here for a good SUN post on all the EJB reference stuff :-<br \/>\n<a href=\"https:\/\/glassfish.dev.java.net\/javaee5\/ejb\/EJB_FAQ.html\">https:\/\/glassfish.dev.java.net\/javaee5\/ejb\/EJB_FAQ.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Much of this has already been covered here, but I am posting these somewhat raw notes from an earlier\u00a0investigative email as they include one or two links and points\u00a0not covered elsewhere. I don&#8217;t have the time or inclination at present to rework everything into an existing post :- \u00a0 1\/ For local beans, you can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[18,19,15],"_links":{"self":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/882"}],"collection":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=882"}],"version-history":[{"count":4,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/882\/revisions"}],"predecessor-version":[{"id":885,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/882\/revisions\/885"}],"wp:attachment":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}