postgresql_PostgreSQL开放自由
postgresql
Open Liberty是源自WebSphere Liberty的有趣的新型OSS Java EE應(yīng)用服務(wù)器。 您可以將Open Liberty配置為使用PostgreSQL作為其默認(rèn)數(shù)據(jù)源,如下所示:
將<datasource> , <jdbcDriver>和<library>指令添加到server.xml配置中:
<?xml version="1.0" encoding="UTF-8"?> <server description="OpenLiberty Java EE 8 Server"><featureManager><feature>javaee-7.0</feature></featureManager><httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443"/><keyStore id="defaultKeyStore" password="Liberty"/><!-- Postgres coffee-shop-db definition --><dataSource id="DefaultDataSource"jndiName="jdbc/sample"jdbcDriverRef="postgresql-driver"type="javax.sql.ConnectionPoolDataSource"transactional="true"><properties serverName="coffee-shop-db"portNumber="5432"databaseName="postgres"user="postgres"password="postgres"/></dataSource><jdbcDriver id="postgresql-driver"javax.sql.XADataSource="org.postgresql.xa.PGXADataSource"javax.sql.ConnectionPoolDataSource="org.postgresql.ds.PGConnectionPoolDataSource"libraryRef="postgresql-library"/><library id="postgresql-library"><fileset id="PostgreSQLFileset" dir="/opt/ol/wlp/lib"includes="postgresql-9.4-1201.jar"/></library></server>通過(guò)主機(jī)coffee-shop-db可用coffee-shop-db將通過(guò)默認(rèn)的Postgres端口5432使用postgres作為數(shù)據(jù)庫(kù)名稱,用戶名和密碼)訪問(wèn)。
驅(qū)動(dòng)程序庫(kù),這里是postgresql-9.4-1201.jar ,需要駐留在服務(wù)器安裝的lib/目錄中。
可以從Java EE應(yīng)用程序透明地使用默認(rèn)數(shù)據(jù)源。 在persistence.xml文件中只需指定一個(gè)持久性單元,類似于以下代碼片段:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistencehttp://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"><persistence-unit name="prod" transaction-type="JTA"/></persistence>如果應(yīng)用程序包含多個(gè)數(shù)據(jù)庫(kù),則要求持久性單元指定其相應(yīng)數(shù)據(jù)源的JNDI名稱。
經(jīng)過(guò)官方Docker鏡像open-liberty:javaee7 。
翻譯自: https://www.javacodegeeks.com/2018/01/postgresql-open-liberty.html
postgresql
總結(jié)
以上是生活随笔為你收集整理的postgresql_PostgreSQL开放自由的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Spring Boot和Apache C
- 下一篇: 很多人不知道淘汰的旧电脑要怎么处理淘汰旧