java - Trouble using @Resource and JNDI lookup -
i'm having trouble applying concept of injection , jndi ejbs , i'd help. learning , want understand , apply techniques of @resource and/or jndi lookups xml configuration. can't seem find of initial parameters in jndi lookups. now, before continue, if manually enter jndi name of datasource, works great. i'm trying (again exercise) use @resource or jndi jndi datasource name , jndi lookup on datasource. know can directly inject datasource object if can't inject string, gotta start this.
first, here's important part of ejb-jar.xml:
<env-entry> <description>datasource jndi lookup name</description> <env-entry-name>datasourcename</env-entry-name> <env-entry-type>java.lang.string</env-entry-type> <env-entry-value>mydatasource</env-entry-value> </env-entry>
in terms of injection using @resource i've tried i've tried following field in ejb
@resource(name = "datasourcename") string dsname;
i've tried mappedname , lookup (using jndi lookup) nothing coming in. i've tried jndi lookup follows:
// jndi name environment entry in ejb context , use lookup datasource context context = new initialcontext(); string dsname = (string) context.lookup("java:comp/env/srs/datasourcename");
(the name of application srs) - comes namingexception jndi lookup did not find anything. i've tried following lookups:
string datasourcename = (string) context.lookup("java:comp/env/srs/status/datasourcename"); // name of ejb status string datasourcename = (string) context.lookup("datasourcename"); string datasourcename = (string) context.lookup("srs/datasourcename"); string datasourcename = (string) context.lookup("srs/status/datasourcename"); string datasourcename = (string) context.lookup("java:global/srs/datasourcename"); string datasourcename = (string) context.lookup("java:global/srs/status/datasourcename");
my first post here hope asked properly. help!
ok. 2 days later saw mistake in code of ejb in configuration of jsp invoked ejb!! mistake had somehow invoked methods of ejb class pojo , not through container. had assumed since ejb methods being called container had correctly injected ejb jsp. didn't. put in jndi lookup in jsp , resolved itself. responses!
Comments
Post a Comment