我有一个WebSphere Liberty 16.0.0.2 webapp,我使用JPA在我的笔记本电脑上本地开发和运行,使用JPA来处理数据库。我以前用SQLDB将它部署到Bluemix(2016年5月由IBM退役),并且它在服务的自动连接方面都运行良好。由于SQLDB不再可用,我能在Bluemix上找到的唯一免费SQL是ElephantSQL,但是自动装配似乎不起作用。以下是部署后出现的错误:
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]].
我上传网络应用的方式是打包服务器并使用cf push
命令。以下是生成的server.xml文件:
<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不提供免费计划。
答案 0 :(得分:3)
报告的异常说明如下:
A valid JDBC driver implementation class was not found
for the jdbcDriver jdbcDriver[myDerbyJDBCdriver]
此异常表示无法在postgresql-jdbc-9.4.1209.jar
中找到Connection Pooling DataSource类。
WLP正在设计中,需要在server.xml中进行额外配置,因为WLP只能找到一定数量的已知数据库的实现类[1]。我查看了postgresql-jdbc-9.4.1209.jar
驱动程序,发现实现类如下:
org.postgresql.ds.PGPoolingDataSource
您应该使用以下内容更新server.xml文件:
javax.sql.DataSource="org.postgresql.ds.PGPoolingDataSource"
答案 1 :(得分:3)
对于使用PostgreSQL(ElephantSQL使用的JDBC驱动程序),您需要在<jdbcDriver>
元素上指定数据源实现类名称:
<jdbcDriver id="myDerbyJDBCdriver" javax.sql.DataSource="org.postgresql.ds.PGPoolingDataSource">
<!-- keep nested stuff the same -->
</jdbcDriver>
你需要为PostgreSQL而不是为Derby指定DataSource impl类的原因是因为Derby是一个已知的&#34;已知&#34;数据库到Liberty,但是PostgreSQL。
我会让Liberty开发人员了解这一点,以便PostgreSQL可以添加为&#34;已知&#34;数据库将来某个时候。