JRuby:JNDI 与 JDBCMYSQL
不确定这两个是否可以比较,请耐心等待。但是(在 JRuby 应用程序中)运行类似于以下的配置的优势是什么:
production:
adapter: jdbc
encoding: utf8
jndi: java:comp/env/app
pool: 200
与:
production:
adapter: jdbcmysql
encoding: utf8
database: tgc
#socket: /var/lib/mysql/mysql.sock
host: localhost
port: 3306
username: mysql
password: notarealpassword
一个比另一个更灵活?我可以更好地调整 JNDI 吗?我问的原因是因为当我使用上面的 JNDI 版本时,我的 Resque 工作人员无法访问数据库。我必须使用后一种配置才能正常工作。
Not sure if these two can be compared, to bear with me. But what is the advantage (in a JRuby application) to run a configuration that's similar to:
production:
adapter: jdbc
encoding: utf8
jndi: java:comp/env/app
pool: 200
versus:
production:
adapter: jdbcmysql
encoding: utf8
database: tgc
#socket: /var/lib/mysql/mysql.sock
host: localhost
port: 3306
username: mysql
password: notarealpassword
Is one more flexible than the other? Can I better tune with JNDI? The reason I ask is because my Resque workers cannot access the DB when I use the JNDI version above. I have to use the latter configuration for things to work properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

JNDI 将数据库配置抽象到应用程序服务器中。好处包括能够利用不同的数据库和/或数据库特征跨服务器部署相同的应用程序,而无需更改应用程序本身。
这通常更多的是政策/管理问题——以这种方式保持数据库内容隔离可以在管理方面提供更大的灵活性;事情可以在应用程序(必然)不知道的情况下重新调整。 (当然,在现实生活中,它并不总是这样工作。)如果管理数据库/服务器的人员与编写/部署应用程序的人员不同,JNDI 可能会非常有帮助。
这种抽象可以通过其他方式进行管理——Rails 使用数据库配置文件,Spring 可能使用特定于服务器的配置文件、系统属性等等。差异较少是技术性的,更多的是管理性的。
JNDI abstracts DB configuration into the app server. Benefits include being able to deploy the same app across servers utilizing different DBs and/or DB characteristics without changing the application itself.
It's often more a matter of policy/administration than anything else--keeping DB stuff isolated in this way gives more flexibility on the administrative side of things; things can be re-jiggered without the app (necessarily) being aware. (It doesn't always work like that in real life, naturally.) If the people managing the DBs/servers aren't the same people writing/deploying the app, JNDI can be very helpful.
That abstraction is manageable in other ways--Rails uses the DB config file, Spring might use server-specific config files, system properties, whatever. The differences are less technical, more managerial.