av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

使用Maven配置JBoss、Wildfly數(shù)據(jù)源

大多數(shù)Java EE應(yīng)用在其業(yè)務(wù)邏輯層中會(huì)訪問數(shù)據(jù)庫,所以開發(fā)者會(huì)經(jīng)常需要為應(yīng)用服務(wù)器配置數(shù)據(jù)庫驅(qū)動(dòng)和數(shù)據(jù)庫連接。這篇文章會(huì)討論如何用Maven自動(dòng)化JBoss、Wildfly和Postgre數(shù)據(jù)庫的配置。

創(chuàng)新互聯(lián)公司專注于城關(guān)網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供城關(guān)營銷型網(wǎng)站建設(shè),城關(guān)網(wǎng)站制作、城關(guān)網(wǎng)頁設(shè)計(jì)、城關(guān)網(wǎng)站官網(wǎng)定制、小程序開發(fā)服務(wù),打造城關(guān)網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供城關(guān)網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

Maven 配置

讓我們從下面的pom.xml 開始吧,

Wildfly Maven Plugin

 
 
  1.  
  2.     org.wildfly.plugins 
  3.     wildfly-maven-plugin 
  4.     1.0.2.Final 
  5.      
  6.          
  7.             false 
  8.             %MINIFYHTML7db47c7a4774fb3aa46c5ca8120866ec8% 
  9.          
  10.      
  11.      
  12.          
  13.             org.postgresql 
  14.             postgresql 
  15.             9.3-1102-jdbc41 
  16.          
  17.      
  18.  

我們開始使用Wildfly Maven Plugin在應(yīng)用服務(wù)器執(zhí)行命令腳本。我們已經(jīng)添加了 Postgre的依賴, Maven會(huì)下載依賴, 因?yàn)槲覀儗⒁诤竺姘阉拥椒?wù)器中。這里有一個(gè) ${cli.file} 屬性, 將指明將執(zhí)行哪一個(gè)腳本。

讓我們?cè)趐om.xml中添加下面內(nèi)容:

Maven Resources Plugin

 
 
  1.  
  2.     org.apache.maven.plugins 
  3.     maven-resources-plugin 
  4.     2.6 
  5.      
  6.          
  7.             copy-resources 
  8.             process-resources 
  9.              
  10.                 copy-resources 
  11.              
  12.              
  13.                 ${basedir}/target/scripts 
  14.                  
  15.                      
  16.                         src/main/resources/scripts 
  17.                         true 
  18.                      
  19.                  
  20.                  
  21.                     ${basedir}/src/main/resources/configuration.properties 
  22.                  
  23.              
  24.          
  25.      
  26.  

用這個(gè)插件,我們可以過濾包含在src/main/resources/scripts這個(gè)目錄中的腳本。使用${basedir}/src/main/resources/configuration.properties這個(gè)文件中的屬性進(jìn)行替換。

最后添加一些 Maven屬性到pom.xml文件中:

Maven Profiles

 
 
  1.  
  2.      
  3.         install-driver 
  4.          
  5.             wildfly-install-postgre-driver.cli 
  6.          
  7.      
  8.  
  9.      
  10.         remove-driver 
  11.          
  12.             wildfly-remove-postgre-driver.cli 
  13.          
  14.      
  15.  
  16.      
  17.         install-wow-auctions 
  18.          
  19.             wow-auctions-install.cli 
  20.          
  21.      
  22.  
  23.      
  24.         remove-wow-auctions 
  25.          
  26.             wow-auctions-remove.cli 
  27.          
  28.      
  29.  

Wildfly Script Files

添加驅(qū)動(dòng)

添加驅(qū)動(dòng)的腳本:

wildfly-install-postgre-driver.cli

 
 
  1. # Connect to Wildfly instance 
  2. connect 
  3.  
  4. # Create Oracle JDBC Driver Module 
  5. # If the module already exists, Wildfly will output a message saying that the module already exists and the script exits. 
  6. module add \ 
  7.     --name=org.postgre \ 
  8.     --resources=${settings.localRepository}/org/postgresql/postgresql/9.3-1102-jdbc41/postgresql-9.3-1102-jdbc41.jar \ 
  9.     --dependencies=javax.api,javax.transaction.api 
  10.  
  11. # Add Driver Properties 
  12. /subsystem=datasources/jdbc-driver=postgre: \ 
  13.     add( \ 
  14.         driver-name="postgre", \ 
  15.         driver-module-name="org.postgre") 

數(shù)據(jù)庫驅(qū)動(dòng)作為Wildfly的一個(gè)模塊(Module)。這樣數(shù)據(jù)庫驅(qū)動(dòng)可以被部署在服務(wù)器中的所有應(yīng)用使用。使用${settings.localRepository} 配置,我們指定數(shù)據(jù)庫驅(qū)動(dòng)下載到你的本地Maven倉庫。還記得我們加到 Wildfly Maven Plugin的依賴嗎,在你插件運(yùn)行的時(shí)候他將下載驅(qū)動(dòng)并加到服務(wù)器中。要運(yùn)行腳本(必須保證應(yīng)用服務(wù)器正在運(yùn)行中)可以執(zhí)行下面的命令:

 
 
  1. mvn process-resources wildfly:execute-commands -P "install-driver" 

需要用process-resources生命周期替換腳本中的屬性。在這個(gè)例子中 ${settings.localRepository} 被替換為 /Users/radcortez/.m3/repository/. 。檢查target/scripts 文件夾。在運(yùn)行命令后,可以在Maven的日志看到以下輸出:

 
 
  1. {"outcome" => "success"} 

服務(wù)器上的日志:

 
 
  1. INFO  [org.jboss.as.connector.subsystems.datasources] (management-handler-thread - 4) JBAS010404: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.3) 
  2. INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) JBAS010417: Started Driver service with driver-name = postgre 

wildfly-remove-postgre-driver.cli

 
 
  1. # Connect to Wildfly instance 
  2. connect 
  3.  
  4. if (outcome == success) of /subsystem=datasources/jdbc-driver=postgre:read-attribute(name=driver-name) 
  5.  
  6.     # Remove Driver 
  7.     /subsystem=datasources/jdbc-driver=postgre:remove 
  8.  
  9. end-if 
  10.  
  11. # Remove Oracle JDBC Driver Module 
  12. module remove --name=org.postgre 

這段腳本是把驅(qū)動(dòng)從你的服務(wù)器上刪除。允許 mvn wildfly:execute-commands -P “remove-driver”,如果你已經(jīng)執(zhí)行了以前的命令就不需要再配置process-resource,除非腳本發(fā)生改變。

添加數(shù)據(jù)源

wow-auctions-install.cli

這個(gè)腳本使用命令添加了一個(gè)數(shù)據(jù)源

wow-auctions-install.cli

 
 
  1. # Connect to Wildfly instance 
  2. connect 
  3.  
  4. # Create Datasource 
  5. /subsystem=datasources/data-source=WowAuctionsDS: \ 
  6.     add( \ 
  7.         jndi-name="${datasource.jndi}", \ 
  8.         driver-name=postgre, \ 
  9.         connection-url="${datasource.connection}", \ 
  10.         user-name="${datasource.user}", \ 
  11.         password="${datasource.password}") 
  12.  
  13. /subsystem=ee/service=default-bindings:write-attribute(name="datasource", value="${datasource.jndi}") 

我們依然需要一個(gè)文件來定義這些屬性。

configuration.properties

 
 
  1. datasource.jndi=java:/datasources/WowAuctionsDS 
  2. datasource.connection=jdbc:postgresql://localhost:5432/wowauctions 
  3. datasource.user=wowauctions 
  4. datasource.password=wowauctions 

Java EE 7 默認(rèn)數(shù)據(jù)源

Java EE 7中, 指定容器必須提供一個(gè)默認(rèn)數(shù)據(jù)源。不要在程序中使用 java:/datasources/WowAuctionsDS JNDI 定義的數(shù)據(jù)源,我們將指定一個(gè)新創(chuàng)建的數(shù)據(jù)源 /subsystem=ee/service=default-bindings:write- attribute(name=”datasource”, value=”${datasource.jndi}”)。 這樣就無需改變程序中的任何配置。 執(zhí)行 mvn wildfly:execute-commands -P “install-wow-auctions”,就可以得到以下輸出:

 
 
  1. org.jboss.as.cli.impl.CommandContextImpl printLine 
  2. INFO: {"outcome" => "success"} 
  3. {"outcome" => "success"} 
  4. org.jboss.as.cli.impl.CommandContextImpl printLine 
  5. INFO: {"outcome" => "success"} 
  6. {"outcome" => "success"} 

服務(wù)器日志:

 
 
  1. INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) JBAS010400: Bound data source 

wow-auctions-remove.cli

 
 
  1. # Connect to Wildfly instance 
  2. connect 
  3.  
  4. # Remove Datasources 
  5. /subsystem=datasources/data-source=WowAuctionsDS:remove 
  6.  
  7. /subsystem=ee/service=default-bindings:write-attribute(name="datasource", value="java:jboss/datasources/ExampleDS") 

上面是刪除數(shù)據(jù)源轉(zhuǎn)為Java EE 7 默認(rèn)數(shù)據(jù)源的腳本。執(zhí)行時(shí)用這個(gè)命令:mvn wildfly:execute-commands -P "remove-wow-auctions"。

總結(jié)

這篇博客展示了如何自動(dòng)在Wildfly實(shí)例中添加刪除添加驅(qū)動(dòng)和數(shù)據(jù)源。如果需要在不同數(shù)據(jù)庫之間切換或者打算重頭配置服務(wù)器,本文的內(nèi)容會(huì)對(duì)你非常有幫助。在做持續(xù)集成(CI)時(shí),這些腳本稍作調(diào)整就可以轉(zhuǎn)到其他驅(qū)動(dòng)。

你可以在這里得到代碼WoW Auctions Github repo。

原文鏈接: javacodegeeks 翻譯: ImportNew.com - 孫 彪彪
譯文鏈接: http://www.importnew.com/13718.html


分享題目:使用Maven配置JBoss、Wildfly數(shù)據(jù)源
當(dāng)前網(wǎng)址:http://uogjgqi.cn/article/coccpjp.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流