[Java] 部署 Spring Application 到 JBoss EAP / Wildfly 中運行

除了Tomcat 外, JBoss / Wildfly 都是熱門的Java Application Server. 與前者比較, JBoss / Wildfly 對整合 Java Enterprise Edition (JEE) 較佳. 而將spring 部署到 JBoss 中雖然較少, 但其穩定性則相對較佳. 示範中會利用Gradle spring application project 進行部署.

  1. 修改application property 檔案.
    /src/main/resources/application.properties 中, 加入以下設定.

    server.servlet.path = /*
    spring.jmx.enabled=false

    server.servlet.path 用作於JBoss 中設定其servlet directory; 而spring.jmx.enabled 則須要disabled 因為當兩個spring boot application 啟動時會產生Unable to register MBean 錯誤.

  2. 修改gradle 設定.
    開啟build.gradle 並修改內容如下.

    apply plugin: 'war'
    
    dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    	{
    		exclude group: "org.springframework.boot"
          	exclude module: "spring-boot-starter-tomcat"
    	}
    }

    因為spring boot 內建tomcat 設定, 會令deployment 時出現ClassCastException, 所以須要exclude tomcat starter package. 而在deployment 時亦會以war 檔形式. 故須加入apply plugin.

  3. 建立war 檔.
    Gradle Task 中選取project, 打開build 並右鍵選取build, 按Run Gradle Task.
  4. 進行部署.
    %PROJECT_DIR%\libs\ 中的war 檔放到JBoss 的deployment 文件夾 (%JBOSS_HOME%\standalone\deployments\)中. 若JBoss 正在運作中的話, 會自動進行deployment, 順利的話, 會見到.deployed 檔出現.
  5. 進行測試.
    於瀏覽器中輸入網址http://localhost:8080/<<war 檔名稱>>/ , 若有結果出現, 代表測試成功.
About C.H. Ling 262 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.