2017-04-14 140 views
1

我想在Mac OS上的Wildfly 10應用程序服務器中配置PostgreSQL數據源。我正在按照說明書的規定進行操作。我已經創建了一個命令:wildfly中的數據源配置10

/wildfly-10.1.0.Final/modules/system/layers/base/org/postgresql/main. 

在此爲了我已經把JDBC驅動程序:

postgresql-9.3-1104.jdbc4.jar 

,我創建了一個module.xml文件:

<?xml version="1.0" encoding="UTF-8"?> 
<module xmlns="urn:jboss:module:1.3" name="org.postgresql「> 
    <resources> 
    <resource-root path="postgresql-9.3-1104.jdbc4.jar"/> 
    </resources> 
    <dependencies> 
    <module name="javax.api"/> 
    <module name="javax.transaction.api"/> 
    </dependencies> 
</module> 

在standalone.xml文件我在datasources下創建了數據源:

 <datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS" enabled="true" 
         use-java-context="true"> 
    <connection-url>jdbc:postgresql://localhost:5432/testdb</connection-url> 
     <driver>postgresql</driver> 
      <security> 
      <user-name>user</user-name> 
      <password>password</password> 
      </security> 
      <validation> 
       <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"></valid-connection-checker> 
       <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"></exception-sorter> 
    </validation> 
    </datasource> 

和驅動程序爲:

<drivers> 
    <driver name="postgresql" module="org.postgresql"> 
    <datasource-class>org.postgresql.Driver</datasource-class> 
    <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class> 
    </driver> 
</drivers> 

然而這是不可能沒有安裝數據源,當我啓動服務器我得到的消息(錯誤):

ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([ 
      ("subsystem" => "datasources"), 
      ("data-source" => "PostgresDS") 
     ]) - failure description: { 
      "WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.postgresql"], 
      "WFLYCTL0180: Services with missing/unavailable dependencies" => [ 
       "org.wildfly.data-source.PostgresDS is missing [jboss.jdbc-driver.postgresql]", 
       "jboss.driver-demander.java:jboss/datasources/PostgresDS is missing [jboss.jdbc-driver.postgresql]" 
      ] 
     } 
    [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([ 
     ("subsystem" => "datasources"), 
     ("data-source" => "PostgresDS") 
    ]) - failure description: { 
     "WFLYCTL0412: Required services that are not installed:" => [ 
      "jboss.jdbc-driver.postgresql", 
      "jboss.jdbc-driver.postgresql" 
     ], 
     "WFLYCTL0180: Services with missing/unavailable dependencies" => [ 
      "org.wildfly.data-source.PostgresDS is missing [jboss.jdbc-driver.postgresql]", 
      "jboss.driver-demander.java:jboss/datasources/PostgresDS is missing [jboss.jdbc-driver.postgresql]", 
      "org.wildfly.data-source.PostgresDS is missing [jboss.jdbc-driver.postgresql]" 
     ] 
    } 

看來,這wildfly也許沒有找到該模塊。任何想法是什麼導致這個問題?我的配置有什麼問題嗎?

+0

我在 org.postgresql改變了數據源類。 xa.PGXADataSource,然後配置成功。 – arjacsoh

回答

6

我想推薦對您的流程進行更改。雖然你當然可以手動做到這一點,但如果你編寫腳本,你可以重複執行。

這取決於jboss-cli.sh。我有一個腳本,看起來像:

embed-server --std-out=echo --server-config=standalone.xml 

batch 

module add --name=org.postgres --resources=/tmp/postgresql-42.0.0.jar --dependencies=javax.api,javax.transaction.api 

/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver) 

/subsystem=datasources/data-source=myDataSource/:add(connection-url=jdbc:postgresql://localhost:5432/thedatabasename,driver-name=postgres,jndi-name=java:/jdbc/myDataSource,initial-pool-size=4,max-pool-size=64,min-pool-size=4,password=theDatabasePassword,user-name=theDatabaseUsername) 

run-batch 

這與運行:

bin/jboss-cli.sh --file=/path/to/file/wildflyconf.cli 

腳本開始通過「嵌入服務器」命令,這樣Wildfly實例並不需要運行。然後啓動一批命令作爲一個單元運行。

重要的是我們通過命令行創建模塊。您必須將PostgreSQL jar放在某個地方,除了腳本需要在「模塊」下創建所有需要的文件。

接下來,我們添加JDBC驅動程序,然後根據驅動程序創建一個數據源。

腳本的優點是你可以檢查到你的源代碼控制系統,任何人都可以運行它。它減少了錯字的可能性,而且您不需要手動創建和修改文件。

只是一個想法。開發團隊可以使用的可重複流程始終是有用的。

0

您要定義Driver類作爲數據源類:

<datasource-class>org.postgresql.Driver</datasource-class> 

請使用正確的元素:

<driver-class>org.postgresql.Driver</driver-class> 

就像@stdunbar表明你在他的CLI命令:

/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver) 
0

在您的文件module.xml中第二行更改

<module xmlns="urn:jboss:module:1.3" name="org.postgresql「> 

<module xmlns="urn:jboss:module:1.3" name="org.postgresql"> 

的 '' 可能是問題在你的module.xml