日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring Batch作为Wildfly模块

發布時間:2023/12/3 javascript 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Batch作为Wildfly模块 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

長期以來,Java EE規范缺少批處理API。 今天,這對于企業應用程序來說是必不可少的。 這是最后固定與JSR-352批處理應用程序的Java平臺現在的Java EE提供7 JSR-352得到了它的的靈感Spring Batch的對手。 兩者涵蓋相同的概念,盡管生成的API有所不同。

由于Spring團隊也參與了JSR-352的合作,因此他們提供基于Spring Batch的實現只是時間問題。 Spring Batch的最新主版本(版本3)現在支持JSR-352 。

我是Spring Batch的用戶很多年了,我一直很喜歡該技術具有一組有趣的內置讀寫器。 這些使您可以執行批處理所需的最常見操作。 您需要從數據庫讀取數據嗎? 您可以使用JdbcCursorItemReader ,如何以固定格式寫入數據? 使用FlatFileItemWriter ,依此類推。

不幸的是, JSR-352實現沒有Spring Batch中可用的讀寫器數量。 我們必須記住, JSR-352是非常新的,沒有時間跟上。 jBeret ( JSR-352的Wildfly實現)已經提供了一些自定義的讀取器和寫入器。

重點是什么?

我希望在最新版本中,也可以使用原始Spring Batch中的所有讀者和作家。 目前還不是這樣,因為需要大量工作,但是已經計劃在將來的版本中提供它們。 這將使我們能夠將本地Spring Batch應用程序遷移到JSR-352中 。 我們仍然存在實現供應商鎖定的問題,但是在某些情況下這可能很有趣。

動機

我是JSR-352規范中的Java EE示例的主要測試貢獻者之一。 我想弄清楚使用Spring Batch實現,我實現的測試是否具有相同的行為。 我們該怎么做?

我認為該練習不僅因為原始動機而有趣,而且對于了解Wildfly上的模塊和類加載也很有用。 首先,我們需要決定如何部署所需的Spring Batch依賴項。 我們可以直接在應用程序中部署它們,也可以使用Wildfly模塊。 模塊的優點是可以直接捆綁到應用程序服務器中,并且可以被所有已部署的應用程序重用。

使用Maven添加Wildfly模塊

通過一些工作,可以使用Wildfly Maven插件和CLI(命令行)自動添加模塊。 讓我們開始創建兩個文件,它們代表創建和刪除模塊所需的CLI命令:

wildfly-add-spring-batch.cli

wildfly-add-spring-batch.cli

# Connect to Wildfly instance connect# Create Spring Batch Module # If the module already exists, Wildfly will output a message saying that the module already exists and the script exits. module add \--name=org.springframework.batch \--dependencies=javax.api,javaee.api \--resources=${wildfly.module.classpath}

模塊--name很重要。 我們將需要它在我們的應用程序中引用它。 --resources很--resources ,因為您需要為所有必需的模塊依賴項指定完整的類路徑,但是在接下來的幾步中,我們將生成路徑。

wildfly-remove-spring-batch.cli

wildfly-remove-spring-batch.cli

# Connect to Wildfly instance connect# Remove Oracle JDBC Driver Module module remove --name=org.springframework.batch

注意wildfly.module.classpath 。 該屬性將保存所需的Spring Batch依賴項的完整類路徑。 我們可以使用Maven Dependency插件生成它:

pom-maven-dependency-plugin.xml

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><version>${version.plugin.dependency}</version><executions><execution><phase>generate-sources</phase><goals><goal>build-classpath</goal></goals><configuration><outputProperty>wildfly.module.classpath</outputProperty><pathSeparator>:</pathSeparator><excludeGroupIds>javax</excludeGroupIds><excludeScope>test</excludeScope><includeScope>provided</includeScope></configuration></execution></executions> </plugin>

這將選擇所有依賴項(包括傳遞性),排除javax (因為它們已經存在于Wildfly中 )并排除test范圍依賴項。 對于Spring Batch,我們需要以下依賴項:

pom-dependencies.xml

<!-- Needed for Wildfly module --> <dependency><groupId>org.springframework.batch</groupId><artifactId>spring-batch-core</artifactId><version>3.0.0.RELEASE</version><scope>provided</scope> </dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>4.0.5.RELEASE</version><scope>provided</scope> </dependency><dependency><groupId>commons-dbcp</groupId><artifactId>commons-dbcp</artifactId><version>1.4</version><scope>provided</scope> </dependency><dependency><groupId>org.hsqldb</groupId><artifactId>hsqldb</artifactId><version>2.3.2</version><scope>provided</scope> </dependency>

現在,我們需要替換文件中的屬性。 讓我們使用Maven資源插件 :

pom-maven-resources-plugin.xml

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><version>${version.plugin.resources}</version><executions><execution><id>copy-resources</id><phase>process-resources</phase><goals><goal>copy-resources</goal></goals><configuration><outputDirectory>${basedir}/target/scripts</outputDirectory><resources><resource><directory>src/main/resources/scripts</directory><filtering>true</filtering></resource></resources></configuration></execution></executions> </plugin>

這將過濾配置的文件,并將屬性wildfly.module.classpath替換為我們先前生成的值。 這是一個指向本地Maven存儲庫中依賴項的類路徑。 現在,使用Wildfly Maven插件,我們可以執行以下腳本(您需要運行Wildfly ):

pom-maven-wildfly-plugin.xml

<plugin><groupId>org.wildfly.plugins</groupId><artifactId>wildfly-maven-plugin</artifactId><version>${version.plugin.wildfly}</version><configuration><skip>false</skip><executeCommands><batch>false</batch><scripts><!--suppress MavenModelInspection --><script>target/scripts/${cli.file}</script></scripts></executeCommands></configuration> </plugin>

這些配置文件:

pom-profiles.xml

<profiles><profile><id>install-spring-batch</id><properties><cli.file>wildfly-add-spring-batch.cli</cli.file></properties></profile><profile><id>remove-spring-batch</id><properties><cli.file>wildfly-remove-spring-batch.cli</cli.file></properties></profile> </profiles>

(有關pom.xml的完整內容,請pom.xml 此處 )

我們可以通過執行以下命令添加模塊:
mvn process-resources wildfly:execute-commands -P install-spring-batch 。

或通過執行以下命令刪除模塊:
mvn wildfly:execute-commands -P remove-spring-batch 。

該策略適用于要在Wildfly中創建的任何模塊。 考慮添加JDBC驅動程序。 通常,您使用模塊將其添加到服務器中,但是我發現的所有文檔始終都是手動過程。 這對于CI構建非常有用,因此您可以擁有設置環境所需的一切。

使用Spring-Batch

好的,我的模塊在那里,但是如何指示Wildfly代替jBeret使用它呢? 我們需要在應用程序的META-INF文件夾中添加以下文件:

jboss-deployment-structure.xml

jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure><deployment><exclusions><module name="org.wildfly.jberet"/><module name="org.jberet.jberet-core"/></exclusions><dependencies><module name="org.springframework.batch" services="import" meta-inf="import"/></dependencies></deployment> </jboss-deployment-structure>

由于JSR-352使用服務加載程序加載實現,因此唯一可能的結果是加載org.springframework.batch模塊中指定的服務。 您的批處理代碼現在將與Spring Batch實現一起運行。

測試中

github存儲庫代碼中有Arquillian示例測試來演示行為。 檢查下面的參考資料部分。

資源資源

您可以從我的github存儲庫中克隆完整的工作副本。 您可以在此處找到說明進行部署。

野蠅–Spring批

由于我將來可能會修改代碼,因此您可以從1.0版中下載本文的原始源。 或者,克隆存儲庫,并使用以下命令從發行版1.0中檢出標記: git checkout 1.0 。

未來

我仍然需要將此應用于Java EE示例 。 在我的待辦事項清單上。

翻譯自: https://www.javacodegeeks.com/2014/08/spring-batch-as-wildfly-module.html

總結

以上是生活随笔為你收集整理的Spring Batch作为Wildfly模块的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。