On Apr 3, 2008, at 11:47 PM, sujith k wrote:
In our development environment currently we are using mokeEJB and we
are
planning to switch to OpenEJB.
As I am new to OpenEJB and I have some doubts regarding the OpenEJB.
1) In my openejb.xml I have given the resource as
<Resource id="MySqlDS" type="DataSource">
JdbcDriver com.mysql.jdbc.Driver
JdbcUrl jdbc:mysql://localhost:3306/test
UserName root
Password root
</Resource>
How can I lookup this resource in my servlet which is called while
startup itself (I am using Tomcat.)
2) In our current application we are accessing the DataSource as
DataSource ds = (DataSource)context.lookup("java:/MySqlDS"); is it
possible to get the datasouce object like this in OpenEJB?
The absolute simplest way is to annotate your servlet like so:
@Resource(name="MySqlDS")
private DataSource mySqlDS;
We will inject the data source right into your servlet and you don't
have to bother with messy lookups.
On a side note, "java:/MySqlDS" is a non standard jndi name that isn't
portable. The portable way is to use the annotation above or to
declare a <resource-ref> tag in your web.xml with a <resource-ref-
name> like "MySqlDS" and a lookup like "java:comp/env/MySqlDS".
-David