mycoffee
mycoffee

Reputation: 41

Data Source Injection for EJB 3 bean not working for Sevlet

I created a simple EJB

@Stateless
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class MyTestBean implements MyTest{


    @Resource
    private SessionContext ctx;

    @EJB
    private RuntimeConfig runtimeConfig; // another bean that works OK

    @Resource
    private DataSource myDB;

The bean cannot be initialized because myDB cannot be found

com.ibm.wsspi.injectionengine.InjectionException: CWNEN0044E: A resource reference binding could not be found for the following resource references [MyTestBean/myDB]

In Websphere 7, I did create myDB datasource and use "Resource references" to map it to the bean. WHat am I missing? Other beans that simply loads the config from the ejb-jar.xml are working fine Please help. Thank you

Upvotes: 0

Views: 1089

Answers (2)

Arka
Arka

Reputation: 9

As bkail says, you can map this datasource to a physical JNDI at deployment time

I would also suggest:

  1. Add a name to the reference in code i.e. @Resource(JDBC/myDataSource)

  2. Go for "detailed deployment" instead of the quick one (this way you get to map all the references then and there, although you may also modify these after the deployment as well)

  3. Double check if you have configured the data source on your application server properly or not and whether it's scope is correct.

You can ditch ejb-jar.xml and ibm-ejb-jar-bnd.xml when you are using annotations.

If you don't want to use annotations - you can provide this "logical" JNDI in the ejb-jar.xml and the "physical" JNDI in the ibm-ejb-jar-bnd.xml (both under this stateless session bean, google for any confusion in syntax or if you are using an IDE, go via the "design" mode rather editing the xml directly)

Cheers!!

Upvotes: 1

Brett Kail
Brett Kail

Reputation: 33936

You should still be able to map/bind resource references at deploy time. If you're not being prompted for that data source, then I recommend opening a PMR with IBM.

Based on the error message, it appears you're using WebSphere Application Server. As a workaround, you could try manually adding a binding via ibm-ejb-jar-bnd.xml. It's unclear which version you're running (you refer to 7.0 in the past, though 8.0 supports EJB 3.1), but if you're running 8.0, you can also use @Resource(lookup="...") to configure the binding at development time.

Upvotes: 0

Related Questions