Why use JNDI for data sources

后端 未结 5 663
谎友^
谎友^ 2020-12-04 14:29

Can anyone help explain why JNDI should be a preferred way to expose services such as a database / jms?

The posts I run into all talk about the advantage of not havi

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 14:48

    JNDI really shines when you have to move an application between environments: development to integration to test to production. If you configure each app server to use the same JNDI name, you can have different databases in each environment and not have to change your code. You just pick up the WAR file and drop it in the new environment.

    Here are some other assumptions that are crucial to know when judging this answer:

    • I don't have access to the servers on which the code is deployed at all, except for read-only access to logs.
    • The person who writes and packages the code is not the same person who configures and manages the server.
    • Once a WAR file starts on its journey to PROD it cannot be changed again without going back to the beginning. Any testing that's done by QA on the test server must be re-done if the WAR is altered.

    Perhaps you don't see this benefit because you're a lone developer who writes code on a local desktop and deploys right to production.

提交回复
热议问题