首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ElephantSQL在Bluemix中部署自由应用程序时,找不到有效的JDBC驱动程序

使用ElephantSQL在Bluemix中部署自由应用程序时,找不到有效的JDBC驱动程序
EN

Stack Overflow用户
提问于 2016-09-07 20:53:00
回答 2查看 4.6K关注 0票数 3

我有一个JPALiberty16.0.0.2Web应用程序,我在我的笔记本电脑上使用Derby开发并在本地运行它,使用WebSphere来处理数据库。我曾经使用SQLDB将其部署到Bluemix中( IBM于2016年5月退役),并且所有这些都通过服务的自动连接工作得很好。由于SQLDB不再可用,我在Bluemix上找到的唯一免费的SQL是ElephantSQL,然而自动装配似乎不起作用。以下是我在部署后得到的错误:

代码语言:javascript
复制
Program error occured: CWWJP0013E: The server cannot locate the java:comp/env/jdbc/TriReplicatorDB data source for the TriReplicatorPersistenceUnit persistence unit because it has encountered the following exception: javax.naming.NamingException: CWNEN1001E: The object referenced by the java:comp/env/jdbc/TriReplicatorDB JNDI name could not be instantiated. If the reference name maps to a JNDI name in the deployment descriptor bindings for the application performing the JNDI lookup, make sure that the JNDI name mapping in the deployment descriptor binding is correct. If the JNDI name mapping is correct, make sure the target resource can be resolved with the specified name relative to the default initial context. [Root exception is com.ibm.wsspi.injectionengine.InjectionException: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/jdbc/TriReplicatorDB reference. The exception message was: CWNEN1006E: The server was unable to obtain an object for the jdbc/TriReplicatorDB binding with the javax.sql.DataSource type. The exception message was: java.sql.SQLNonTransientException: DSRA4000E: A valid JDBC driver implementation class was not found for the jdbcDriver jdbcDriver[myDerbyJDBCdriver] using the library com.ibm.ws.classloading.sharedlibrary_79. [/home/vcap/app/wlp/usr/servers/triServer/lib/postgresql-jdbc-9.4.1209.jar]]. 

我上传web应用程序的方式是打包服务器并使用cf push命令。以下是生成的server.xml文件:

代码语言:javascript
复制
<server description="new server">
<!-- Enable features -->
<featureManager>
    <feature>jsp-2.3</feature>
    <feature>concurrent-1.0</feature>
    <feature>jaxrs-2.0</feature>
    <feature>jaxrsClient-2.0</feature>
    <feature>jpa-2.1</feature>
    <feature>appSecurity-2.0</feature>
    <feature>localConnector-1.0</feature>
    <feature>icap:managementConnector-1.0</feature>
    <feature>appstate-1.0</feature>
    <feature>jdbc-4.1</feature>
    <feature>cloudAutowiring-1.0</feature>
</featureManager>
<httpEndpoint httpPort="${port}" id="defaultHttpEndpoint" host="*"/>
<webContainer deferServletLoad="false" trustHostHeaderPort="true" extractHostHeaderPort="true"/>
<applicationMonitor updateTrigger="mbean"/>
<!-- This is the application itself -->
<webApplication contextRoot="/" id="Tri-Replicator" location="Tri-Replicator.war" name="Tri-Replicator">
</webApplication>
<jdbcDriver id="myDerbyJDBCdriver">
    <library name="DerbyLib">
        <fileset dir="C:\projects_c\Tri-Replicator-16\db\db-derby-10.11.1.1-bin\lib" includes="derby.jar"/>
        <fileset dir='${server.config.dir}/lib' includes='postgresql-jdbc-9.4.1209.jar'/>
    </library>
</jdbcDriver>
<!-- Use local Derby DB for local testing on laptop, but when deployed into BlueMix this will automatically be rewired to use SQL DB instance -->
<dataSource id="DerbyConnection" jdbcDriverRef="myDerbyJDBCdriver" jndiName="jdbc/TriReplicatorDB">
    <properties createDatabase="create" databaseName="${cloud.services.ElephantSQL-tri-replicator.connection.name}" user="${cloud.services.ElephantSQL-tri-replicator.connection.user}" password="${cloud.services.ElephantSQL-tri-replicator.connection.password}" serverName="${cloud.services.ElephantSQL-tri-replicator.connection.host}" portNumber="${cloud.services.ElephantSQL-tri-replicator.connection.port}"/>
</dataSource>
<include location='runtime-vars.xml'/>
<httpDispatcher enableWelcomePage='false'/>
<config updateTrigger='mbean'/>
<appstate appName='Tri-Replicator' markerPath='${home}/../.liberty.state'/>

作为另一个问题--有没有人能为Bluemix中的SQL数据库提供其他免费的小计划?PostgreSQL和DB2不提供免费套餐。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-07 22:35:03

报告的异常说明如下:

代码语言:javascript
复制
A valid JDBC driver implementation class was not found 
for the jdbcDriver jdbcDriver[myDerbyJDBCdriver]

此异常表示它无法在postgresql-jdbc-9.4.1209.jar中定位连接池DataSource类。

WLP按照设计工作,需要在server.xml中进行额外的配置,因为WLP只能定位特定数量的已知databases1的实现类。我检查了postgresql-jdbc-9.4.1209.jar驱动程序,发现实现类如下:

代码语言:javascript
复制
org.postgresql.ds.PGPoolingDataSource

您应该使用以下内容更新server.xml文件:

代码语言:javascript
复制
javax.sql.DataSource="org.postgresql.ds.PGPoolingDataSource"

1

票数 3
EN

Stack Overflow用户

发布于 2016-09-07 22:39:07

为了使用PostgreSQL (这是ElephantSQL使用的JDBC驱动程序),您需要在<jdbcDriver>元素上指定您的数据源实现类名:

代码语言:javascript
复制
<jdbcDriver id="myDerbyJDBCdriver" javax.sql.DataSource="org.postgresql.ds.PGPoolingDataSource">
  <!-- keep nested stuff the same -->
</jdbcDriver>

需要为PostgreSQL指定Derby类而不是为DataSource指定该类的原因是,Derby对PostgreSQL来说是一个“已知的”数据库,而对PostgreSQL来说是一个“已知的”数据库。

我会让Liberty开发人员知道这一点,这样将来就可以将PostgreSQL添加为一个“已知”的数据库。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39370482

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档