How to Deploy Spring Boot App to Wildfly


Sharing is caring!

Spring Framework

One of the most exciting framework in the Java world is Spring Framework. They offer a lot of useful features, from spring core, spring jms, spring data jpa, spring boot and many more. Those features similar with JEE. However, since Java EE 7 (they said the JEE 8 will be release on 2017), they seem stuck in updates (features). That could make springĀ  kill JEE atrociously. Just like Sub-Zero doing fatality. I know it is a little bit opinionated, but who cares šŸ™‚

Since the beginning of 2016, most of my projects use Spring Boot. And I feel superb. Their parent pom is great. No more agony to solve dependency hell (maven users will understand). They provided a lot of boot starter, from web to the cloud. AND the most notable thing is their wizard on http://start.spring.io. From its website, you can generate project, with less painful, only mentioning dependency. The rest is magic.

Use Case

Alright, too much non-sense for a how to article. Here is the use case. I want to create REST services using Spring Boot. And deploy it on Wildfly.

spring boot wizard
spring boot wizard

First of all, go to http://start.spring.io, fill in Group, Artifact, and Dependencies Web. Select Maven Project and click Generate Project. Within this setup, I have my own tomcat container inside the application. Meaning, all I need only run itsĀ main class in order to start the server. Then create RestController, run the main class, then here comesĀ the REST endpoint.

However, this standard setup is not JEE Application Server friendly, because the default packaging is jar. Meanwhile, I want to deploy into Wildfly. And hereĀ comes the naive thought.Ā “Hmm.. if I changed the packaging into war, everything is solved.” Well, not surprisingly, it did not work. Why? Apparently, I have to tweak two files, pom.xml and main class in order to make it works.

pom.xml

Here are the steps:

  1. Exclude spring-boot-starter-tomcat, and change the scope into provided.
  2. Add maven war plugin
  3. Configure spring-boot-maven-plugin to make it executable WAR. Meaning, you can execute the war files by java -jar Demo.war. Just info, this step is optional if you do not want make an executable WAR.

Main Class

Not much in this part, only extends SpringBootServletInitializer.

After all, run mvn clean package again, get the war then deploy into Wildfly. Then your REST is ready to use.

Enjoy šŸ™‚

PS: this article is running on JDK 1.8, Wildfly 10.0, Spring Boot 1.4.1 and Apache Maven 3.2.3

Reference

https://spring.io/blog/2014/03/07/deploying-spring-boot-applications

Author: ru rocker

I am a professional software developer with more than 10 years experiences. I am a certified Java Developer (SCJP and SCWCD). However, In the recent months, I have more interest in DevOps and start to become a polyglot developer. Python and Go-lang become my favorite programming languages besides Java.

2 thoughts on “How to Deploy Spring Boot App to Wildfly”

    1. Nowadays web.xml is no longer required to create a war file.. You can use annotations instead of web.xml.

      And one of the main thing is extends your main class with SpringBootServletInitializer.

      Is there any error while deploying to wildfly?

Leave a Reply

Your email address will not be published. Required fields are marked *