JNDI(datasource)在tomcat,JBOSS下的spring+quartz配置

      由於項目中多個小應用(類似插件)需要使用數據庫連接池,不能爲每一個應用中配置連接池。故採用JNDI的模式進行配置。

      我們使用的web服務器有tomcat和jboss兩種。分別介紹其在這兩種服務器下並且在兩種應用模式spring+hebernat與quartz下的配置。

tomcat下:

1)在tomcat 6.0下配置JNDI及在Spring中的使用 (引用1)已經詳細介紹了其往spring應用中添加的詳細過程。(引用3)

2)quartz中添加tomcat jndi datasource很簡單,只需要調用org.quartz.dataSource.myDS.jndiURL設置即可。

3)tomcat下quartz中出現 not bound in context的問題是要寫完整的jndi名字。必須加上“java:comp/env/XXX“,查看intialcontext源代碼可知,與spring中名字格式保持一致即可。markmail網站上可以搜到很多這種問題的解決方案(引用2)。

4)(這一點我也不知道爲什麼。)有時我的jndi名字就是不能綁定下來,但是當我把名字儘量縮短就不會出現問題。測試許多次都出現不知道何原因。我的命名是”jndi/abcd“。

5)我嘗試將我的tomcat6.0添加admin模塊(引用5),並使用其添加jndi服務,但是不成功。未曾找到admin配置jndi修改的文件,明顯不是引用1,3中的config目錄下的context文件。

jboss下:

1)jboss下部署配置spring jndi(引用4)詳細介紹jboss下的spring配置。

2)quartz類似tomcat。

3)我曾經嘗試在spring中配置使用跨jvm的jndi的datasource,進行遠程調用。

注意使用<use-java-context>false</use-java-context>可以進行跨jvm調用(引用6)。但是在spring直接進行bean配置會出現問題javax.naming.Resource  javax.sql.DataSource typemismatch。需要手寫一個bean進行這種轉換(強制轉換),可以參考引用6中的例子。(引用7)但是,這裏有一點提醒:Using Datasources from remote is not recommended and might lead into trouble easily because the app server looses control over the connections. Be warned!Once the maximum connection in the pool are reached no other connections can be obtained. For the reason that the server does not manage the connections anymore, he is not aware that you close the connection.考慮到實際情況,最終我放棄了跨JVM的jndi的調用。

--------------------------------------------

現在JNDI工作正常,要進行觀察,適當調整參數,優化服務器性能。

--------------------------------------------------

引用1:在tomcat 6.0下配置JNDI及在Spring中的使用 http://karidyang.javaeye.com/blog/216125

引用2:markmail網站

http://markmail.org/search/?q=quartz+tomcat+jndi

引用3:tomcat+jndi+spring配置

http://apps.hi.baidu.com/share/detail/31393331

引用4:jboss下部署配置spring jndi

http://www.blogjava.net/sxyx2008/archive/2010/09/08/331382.html

引用5:apache-tomcat-6.0.18下配置Tomcat Administration Web Application Tool

http://hi.baidu.com/%B9%C2%B6%C0%5F%CE%E8%D5%DF/blog/item/33c11703785902713812bb49.html

引用6:Access JBoss DataSource Remotely from Java Applications

http://javahowto.blogspot.com/2006/08/access-jboss-datasource-remotely-from.html

引用7:Using JBoss DataSource from standalone client

http://forum.springsource.org/showthread.php?16076-Using-JBoss-DataSource-from-standalone-client

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章