简体   繁体   English

Glassfish资源/ jndi / jdbc登录凭据配置

[英]Glassfish resources/jndi/jdbc login credential configuration

I'm deploying my first Java web service app and just finished solving "Glassfish: Exception while preparing the app : Invalid resource : __pm". 我正在部署我的第一个Java Web服务应用程序,并且刚刚解决了“ Glassfish:在准备应用程序时发生的异常:无效的资源:__ pm”。 I created the glassfish-resources.xml file and placed it in my web-inf folder per http://www.oracle.com/technetwork/articles/java/pongegf-1517943.html . 我创建了glassfish-resources.xml文件,并将其放置在每个http://www.oracle.com/technetwork/articles/java/pongegf-1517943.html的 web-inf文件夹中。 (It took me awhile to realize that Netbeans put the file in the wrong place to start with). (花了一段时间我才意识到Netbeans首先将文件放在错误的位置)。

Now I'm wondering about distribution in the real world where the login credentials are buried in the WAR file via the glassfish-resources.xml file. 现在,我想知道在现实世界中的分布情况,其中登录凭据通过glassfish-resources.xml文件埋在WAR文件中。 Presumably if I ever need to change the credentials, I would have to rebuild for every server configuration I deploy to since my login credentials will be different between environments. 据推测,如果我需要更改凭据,则我必须针对部署到的每个服务器配置进行重建,因为我的登录凭据在环境之间会有所不同。 Since we typically go through 2-3 stages of testing environments before going to production, this seems prone to introducing new errors or changes. 由于我们通常在投入生产之前要经过2-3个测试环境阶段,因此这似乎易于引入新的错误或更改。 Is there a way to maintain the login credentials in a config file that isn't part of the compiled WAR file or am I missing something more fundamental? 有没有办法在配置文件中维护登录凭据,而该配置文件不是已编译的WAR文件的一部分,还是我缺少更基本的东西?

Thank you. 谢谢。

Normally you would setup a JDBC connection pool and use a JDBC resource to reference it. 通常,您将设置一个JDBC连接池并使用JDBC资源来引用它。 In the application you configure the JDBC resource used via the persistence.xml. 在应用程序中,您可以配置通过persistence.xml使用的JDBC资源。

Something like this, when using the default Glassfish derby database (JDBC resource and connection are already setup for this, only the DB must be started): 类似于以下内容,当使用默认的Glassfish derby数据库时(为此已经设置了JDBC资源和连接,仅必须启动DB):

 <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
 <persistence-unit name="my_persistence">
     <jta-data-source>jdbc/__default</jta-data-source>
 </persistence-unit>

So on all your environments you must ensure the JDBC resource has the same name (if you do not want to change the war file) but the actual config can be different, because it is stored in the Glassfish instance and not in your war file. 因此,在所有环境中,您必须确保JDBC资源具有相同的名称(如果您不想更改war文件),但是实际配置可以不同,因为它存储在Glassfish实例中,而不存储在war文件中。

According to comments, as you asked @Trebor for determining DB type at runtime there is way to go through,visit this JDBC connection also 根据评论,当您要求@Trebor在runtime确定DB类型runtime有一种方法可以通过,请访问此JDBC连接

http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html

getClientInfo() getClientInfo()

Entity Manager IN java Java中的实体管理器

http://tomee.apache.org/examples-trunk/injection-of-entitymanager/README.html http://tomee.apache.org/examples-trunk/injection-of-entitymanager/README.html

this will definitely going to solve your issue .all the best .! 绝对可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM