2016-11-17 212 views
1

訪問JNDI的DataSource根據此文件:如何與遊戲框架

https://www.playframework.com/documentation/2.5.x/JavaDatabase#exposing-the-datasource-through-jndi

我只需要在我application.conf另一個條目在JNDI中暴露出一個DataSource:

db.default.driver=org.h2.Driver 
db.default.url="jdbc:h2:mem:play" 
db.default.jndiName=DefaultDS 

我已經"tyrex" % "tyrex" % "1.0.1"添加到我的libraryDepenenciesbuild.sbt中。

從閱讀這幾個其他職位,它聽起來像我應該能夠簡單地使用

DataSource ds = (DataSource) play.api.libs.JNDI.initialContext().lookup("DefaultDS"); 

要提取JNDI數據源。然而,當我嘗試這一點,拋出了以下異常:

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) 

我想這樣做的主要原因是,這樣的石英可以重複使用的,而不是在石英定義另一個通過播放創建的數據源/連接池的.properties。根據文檔:

http://www.quartz-scheduler.org/documentation/quartz-2.x/configuration/ConfigDataSources.html

我應該需要以下兩行quartz.properties

org.quartz.jobStore.dataSource = h2 
org.quartz.dataSource.h2.jndiURL = DefaultDS 

然而,石英拋出一堆例外:

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] 

我不知道下一步該去哪裏。任何幫助,將不勝感激。

謝謝。

回答

0

找到它。

我只需要將jdbc添加到我的libraryDependenciesbuild.sbt。這在JNDI中創建並公開了DataSource。