[英]How to access JNDI DataSource with Play Framework
According to this documentation: 根据这个文件:
https://www.playframework.com/documentation/2.5.x/JavaDatabase#exposing-the-datasource-through-jndi https://www.playframework.com/documentation/2.5.x/JavaDatabase#exposing-the-datasource-through-jndi
I simply need another entry in my application.conf
to expose a DataSource in JNDI: 我只需要在
application.conf
另一个条目来公开JNDI中的DataSource:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
db.default.jndiName=DefaultDS
I've added "tyrex" % "tyrex" % "1.0.1"
to my libraryDepenencies
in build.sbt
. 我已经添加了
"tyrex" % "tyrex" % "1.0.1"
我libraryDepenencies
在build.sbt
。
From reading several other posts on this, it sound like I should be able to simply use 通过阅读其他几篇文章,听起来我应该能够简单地使用
DataSource ds = (DataSource) play.api.libs.JNDI.initialContext().lookup("DefaultDS");
To fetch the DataSource from JNDI. 从JNDI获取DataSource。 However, when I try this it throws the following Exception:
但是,当我尝试这个时,它会抛出以下异常:
javax.naming.NameNotFoundException: DefaultDS not found
at tyrex.naming.MemoryContext.internalLookup(Unknown Source)
at tyrex.naming.MemoryContext.lookup(Unknown Source)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
The main reason I'm trying to do this is so that Quartz can re-use the DataSource/ConnectionPool created by Play instead of defining another in quartz.properties. 我尝试这样做的主要原因是Quartz可以重新使用Play创建的DataSource / ConnectionPool,而不是在quartz.properties中定义另一个。 According to the docs:
根据文件:
http://www.quartz-scheduler.org/documentation/quartz-2.x/configuration/ConfigDataSources.html http://www.quartz-scheduler.org/documentation/quartz-2.x/configuration/ConfigDataSources.html
I should need the following two lines in quartz.properties
: 我应该在
quartz.properties
需要以下两行:
org.quartz.jobStore.dataSource = h2
org.quartz.dataSource.h2.jndiURL = DefaultDS
However, Quartz throws a bunch of exceptions: 但是,Quartz抛出了一堆例外:
java.sql.SQLException: Could not retrieve datasource via JNDI url 'DefaultDS' javax.naming.NameNotFoundException: DefaultDS not found [See nested exception: java.sql.SQLException: Could not retrieve datasource via JNDI url 'DefaultDS' javax.naming.NameNotFoundException: DefaultDS not found]
I'm not sure where to go next. 我不知道下一步该往哪里去。 Any help would be appreciated.
任何帮助,将不胜感激。
Thanks. 谢谢。
Found it. 找到了。
I simply needed to add jdbc
to my libraryDependencies
in build.sbt
. 我只需要将
jdbc
添加到libraryDependencies
中的build.sbt
。 This created and exposed the DataSource in JNDI. 这在JNDI中创建并公开了DataSource。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.