Sunday, 15 March 2015

java - Using Initial Context with Play Framework instead of Tomcat -



java - Using Initial Context with Play Framework instead of Tomcat -

so have basic dao class makes connection using initialcontext lookup tomcat , spring , works perfectly:

context initctx = new initialcontext(); initialize((datasource) initctx.lookup(resourcename));

now, have extended basic dao , using kid class in play framework application. initial context lookup, however, not work on play application. error says:

caused by: javax.naming.notcontextexception: comp not subcontext @ tyrex.naming.envcontext.internallookup(unknown source) ~[tyrex-1.0.1.jar:1.0.1 nov 11 2003 1703] @ tyrex.naming.envcontext.lookup(unknown source) ~[tyrex-1.0.1.jar:1.0.1 nov 11 2003 1703] @ tyrex.naming.java.javacontext.lookup(unknown source) ~[tyrex-1.0.1.jar:1.0.1 nov 11 2003 1703] @ javax.naming.initialcontext.lookup(initialcontext.java:417) ~[na:1.8.0] @ databasefactory.<init>(databasefactory.java:63) ~[utilities-snapshot.jar:na]

is there anyway utilize initial context lookup function while still using play framework?

play's jndi environment provided in-memory jndi service provider. there play helper class can utilize hold of initialcontext called play.api.libs.jndi. can utilize lookup datasource.

using this benchmark test app illustration , adding next action:

public application extends controller { ... public static result getdatasource() throws namingexception { datasource datasource = (datasource) play.api.libs.jndi.initialcontext().lookup("defaultds"); homecoming ok(datasource.tostring()); } }

would lookup datasource bound name defaultds in application.conf

looking @ exception, seems you're looking initialcontext , resources java:comp/.../resourcename in utility library. won't play (excuse pun) in play app out of box. suggest lookup datasource in play specific way, per illustration above.

java spring scala tomcat playframework-2.0

No comments:

Post a Comment