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.
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.
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.
Not much in this part, only extends
After all, run
mvn clean package again, get the war then deploy into Wildfly. Then your REST is ready to use.
PS: this article is running on JDK 1.8, Wildfly 10.0, Spring Boot 1.4.1 and Apache Maven 3.2.3