How to Deploy Spring Boot App to Wildfly
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.
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:
- Exclude spring-boot-starter-tomcat, and change the scope into provided.
- Add maven war plugin
- 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
I followed above steps but don’t find web.xml in the war package. And not able to access the Rest Service by deploying in Wildfly 10.
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?
I followed your step but I am getting the following error:
Error
HTTP method POST is not supported by this URL
Do you have Controller class?
How to Install Java Spring Boot Application on Tomcat or Wildfly Server from : https://atechdaily.com/posts/Deploy-Spring-Boot-Application-On-Server