java ee - From an ear file's application.xml deployment descriptor, how do I override a @ManagedBean's @EJB reference? -


i have @managedbean in .ear file's lib directory.

in @managedbean have this:

@ejb(name = "ejb/fred") // declares ejb reference , names private fred fred; 

in .ear file's meta-inf/application.xml have this:

<ejb-local-ref>   <ejb-ref-name>ejb/fred</ejb-ref-name> <!-- targets reference declared above -->   <local>com.foobar.fred</local>   <ejb-link>some-jar.jar#fredbean</ejb-link> </ejb-local-ref> 

glassfish 3.1.2.2 happily processes , right thing dozens of ejbs have @ejb-annotated fields in them names of ejb/fred: fredbean some-jar.jar ejb jar implementation. no muss, no fuss, spec intended.

but when comes @managedbeans these @ejb-annotated fields, binding doesn't happen.

glassfish 3.1.2.2 throws exception saying there many fred implementations present (which there in case—why i'm in <ejb-local-ref> situation in first place), can't inject fred field.

that is, cannot target @managedbean-hosted @ejb reference named ejb/fred configuration.

the managed bean 1.0 "specification" says, ominously:

a managed bean not have own component-scoped “java:comp” namespace. reason, managed beans should define resources [emphasis mine] in “java:module” namespace or above.

more specifically, means cannot use name attribute of @ejb annotation, because, documentation reads:

the logical name of ejb reference within declaring component's (e.g., java:comp/env) environment.

[edit: ejb specification committee changed language here in response question; raises more questions—it apparently intended should able use "absolute" resource names in name() element.]

[edit: realized can control scope of ejb reference's name 1 of java:module or java:app prefixes, per this. perhaps answer define of <ejb-local-ref>s twice in meta-inf/application.xml: once component environment names, , once java:app names?]

[edit: declaring reference @ejb(name = "java:app/ejb/fred") or @ejb(name = "java:module/ejb/fred")and targeting in myapplication.xml's` elements doesn't work either. believe may straight bug.]

[edit: david blevins' lookup() solution works far goes. lookup() not alternative name(), rather mappedname() , beanname(), neither of which, ideally, want specify on these references, repackaging nightmare. additionally, automatic reference wiring goes out window entirely; using lookup() means you're telling container deployer or assembler manually bind reference here , container should lay off. nightmare sprawling enterprise app.]

is there way use application.xml-level <ejb-link> element target @managedbean-hosted @ejb references?

[edit: i've filed glassfish bug test case.]

try using lookup attribute of @ejb annotation. added in java ee 6 , not visible ide unless you're on java 7 or have added right jars java 6 jvm's endorsed dir. in lookup attribute put jndi name, java:app/ejb/fred or other name under java:app.

then in application.xml create name java:app/ejb/fred , link desired ejb.

<ejb-local-ref>   <ejb-ref-name>java:app/ejb/fred</ejb-ref-name>   <local>com.foobar.fred</local>   <ejb-link>some-jar.jar#fredbean</ejb-link> </ejb-local-ref> 

if doesn't work, might out of luck.

note on @managedbean

@managedbean underdefined , undertested. added late in java ee 6 placeholder in future development , hasn't been further developed. don't recommend using it.

you might, try switching @javax.ejb.singleton or @javax.ejb.stateless service instead of @managedbean, though ideally pojo jax-rs service should have dependency injection without adding @managedbean.

if find helpful, can confirm of above work in tomee. i'm sure glassfish more willing accept patches , in area.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -