File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes OpenEJB, DI Overriding annotation with deployment descriptor Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply Bookmark "OpenEJB, DI Overriding annotation with deployment descriptor" Watch "OpenEJB, DI Overriding annotation with deployment descriptor" New topic
Author

OpenEJB, DI Overriding annotation with deployment descriptor

Marcus Didius Falco
Ranch Hand

Joined: Feb 25, 2007
Posts: 72
I have learned that xml deployment descriptors override annotations.
So I am trying to use that feature to inject a mock implemantion into an EJB for testing:

I am using OpenEJB 3.1.2.



The CreditCardServiceBean gets injected into the TravelAgentBean

I try to override this in the ejb-jar.xml:


however testing the whole setup I see that still the CreditCardServiceBean
is injected.
Only when I remove the @EJB(beanName="CreditCardServiceBean") annotation the CreditCardServiceMock is injected.
I don't think thats the expected behavior.
Is something wrong with my deployment desprictor?
Any help would be appreciated.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 8142
    
  52

Your ejb-ref-name should match the "name" of the @EJB (which by default is classname.fieldname). Try this:




ejb-jar.xml (note the ejb-ref-name now matches the name attribute of @EJB)


[My Blog] [JavaRanch Journal]
David Blevins
Greenhorn

Joined: May 03, 2010
Posts: 18
Good catch, Jaikiran!

A nice override/debug option is to set 'openejb.descriptors.output' to 'true'. With that on the effective runtime descriptor is saved to the temp directory. Then you can take a look to see what your xml and annotations look like combined into the final "one true" descriptor.

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: OpenEJB, DI Overriding annotation with deployment descriptor
 
Similar Threads
ejb3 with javaee client helloworld
EJB3.x XML overriding @EJB Annotation Injection
Problems with EJB3.0... (continued)
Considering Injection i EJB 3.0
getting error when deploying web app in weblogic 10.0