tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kubamarchwicki <k...@marchwicki.pl>
Subject override annotation based configuration with ejb-jar.xml
Date Mon, 27 Jun 2011 20:44:48 GMT
Hi, 
Here is my issue with OpenEJB. I'm note sure if what I'm trying to do is not
possible or I'm doing something wrong. 

I use OpenEJB only for testing - embedded container. In the application I
have multiple beans implementing same business interface, one main - with
logic, few other in tests. What I'm looking for is possibility to (after
bootstrapping container) override wired dependencies with the testing
implementation. 
How I understand OpenEJB lifecycle, first ejb-jar.xml is evaluated. After
that - class path discovery is performed. In either cases it doesn't work
for me. When I put something like this in ejb-jar.xml a NullPointer is
thrown (MethodController is my business service,
AnotherTestingDisplayingService is a testing mockup)
        <session>
            <ejb-name>MethodController</ejb-name>
            <ejb-ref>
               
<ejb-ref-name>pl.marchwicki.ejb.controllers.MethodController/displayingService</ejb-ref-name>
               
<remote>pl.marchwicki.ejb.view.DisplayingServiceLocal</remote>
                <ejb-link>AnotherTestingDisplayingService</ejb-link>
                <injection-target>
                   
<injection-target-class>pl.marchwicki.ejb.controllers.MethodController</injection-target-class>
                   
<injection-target-name>displayingService</injection-target-name>
                </injection-target>
            </ejb-ref>

Sounds reasonable, MethodController is not yet present in context. 

On the other hand, when I fully define MethodController in ejb-jar.xml (like
this)
<session id="MethodController">
            <ejb-name>MethodController</ejb-name>
            <mapped-name></mapped-name>
           
<business-local>pl.marchwicki.ejb.controllers.MethodControllerLocal</business-local>
           
<ejb-class>pl.marchwicki.ejb.controllers.MethodController</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>
            <ejb-ref>
               
<ejb-ref-name>pl.marchwicki.ejb.controllers.MethodController/displayingService</ejb-ref-name>
               
<remote>pl.marchwicki.ejb.view.DisplayingServiceLocal</remote>
                <ejb-link>AnotherTestingDisplayingService</ejb-link>
                <injection-target>
                   
<injection-target-class>pl.marchwicki.ejb.controllers.MethodController</injection-target-class>
                   
<injection-target-name>displayingService</injection-target-name>
                </injection-target>
            </ejb-ref>
            <ejb-ref>
               
<ejb-ref-name>pl.marchwicki.ejb.controllers.MethodController/calculatingService</ejb-ref-name>
               
<remote>pl.marchwicki.ejb.business.CalculatingServiceLocal</remote>
                <injection-target>
                   
<injection-target-class>pl.marchwicki.ejb.controllers.MethodController</injection-target-class>
                   
<injection-target-name>calculatingService</injection-target-name>
                </injection-target>
            </ejb-ref>
        </session>  

I get javax.naming.NameAlreadyBoundException when classpath discovery is
performed. 
Either way my mocking doesn't work. 

Similar problem happens when multiple ears are collapsed into single
classpath.ear (on tests). When multiple implementations of same business
interface are present across different ears, there is not way in OpenEJB to
manually pick up desired implementation. 

My question is - am I doing something wrong or I'm trying to 'beat the game'
and doing things which OpenEJB wasn't designed for.

The code for this example is on my github
(https://github.com/kubamarchwicki/ejb-testing) if some reference is needed.

many thanks
Jakub

--
View this message in context: http://openejb.979440.n4.nabble.com/override-annotation-based-configuration-with-ejb-jar-xml-tp3628806p3628806.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Mime
View raw message