Ad Code

Sunday, June 30, 2019

Preparing your Spring Boot app to deploy it to JBoss EAP 6.3


Hello Everyone,

Being an AEM Developer. You are supposed to know how to use java frameworks. So
in my industry experience I got an opportunity to work with spring boot many times. Working with spring boot framework is one of the easiest things to do because spring
boot applications runs on its own tomcat server and you don't need to have a big setup for
this.

But sometimes clients want to deploy spring boot applications in JBoss server and if
JBoss server is quite legacy like JBoss EAP 6.3 or older than this then the actual problem
starts.

So my requirement was client wants me to make a spring boot application which can run on
java 7 and 8 and can be deployed over JBoss EAP 6.3.

As spring boot 2 needs java 8 to run so I am not able to use that so I decided to use spring
boot version 1.5.21.RELEASE as it works on both java 7 and 8.

Let’s create a basic Application with spring boot and deploy it in JBoss 6.3.
Prerequisites:
  1. Install JBoss EAP 6.3 : You can download JBoss 6.3 installer from here. For step by step procedure to install it in windows, please go through with this video.
  2. Create a sample spring boot project: To create a sample spring boot project, you need to create a project from here. You can see the whole video to how to create a spring project and deploy it in JBoss container.
Till here, I assume that you are already done with prerequisites and now you need to make a few changes in your spring boot project.
  1. Let’s create a sample main class and a very basic hello world API here.
  2. First change the artifact “spring-boot-starter” to “spring-boot-starter-web”, because to create API we need “spring-boot-starter-web” dependency and web jar also contain the “spring-boot-starter jar in itself.So to avoid duplicacy we need to do it. You need to deploy this application in JBoss container so you need to exclude tomcat dependency from your main spring boot starter web jar.
    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
       <exclusions>
          <exclusion>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-tomcat</artifactId>
          </exclusion>
       </exclusions>
    </dependency>
  3. As javax.servlet dependency was the part of tomcat API and in step 2 we have already excluded tomcat dependency, so we need to add this dependency externally only for compile time as JBoss also has this dependency so at run-time JBoss will take care of it.
  4. <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
       <version>2.5</version>
       <scope>provided</scope>
    </dependency>
  5. Add server.servlet-path=/* in application.properties file.
  6. To deploy it in JBoss container, we need to make a war for the project. To do that we need to add :<packaging>war</packaging>
  7. Define context root:There are many ways to decide the context root of application in JBoss container.
    • Add <finalName> xyz</finalName> in pom.xml inside <build> tag.
    • Add jboss-web.xml inside project directory/webapp/WEB-INF/jboss-web.xml and add this line in the xml file.
      <jboss-web>
         <context-root>/xyz</context-root>
      </jboss-web
That’s all you need to do after that just run the maven command “mvn clean package” and deploy it in the JBoss container.
After you follow the above steps and deploy the application in JBoss, the very first issue comes to you which is:
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS018104: Deployment error processing SCI for jar: logback-classic-1.1.11.jar

To solve this issue, you need to exclude the logback dependency from spring boot starter web dependency. Add this exclusion also in step 2 exclusions list.
<exclusion>
   <groupId>ch.qos.logback</groupId>
   <artifactId>logback-classic</artifactId>
</exclusion>

After this you again deploy the application in JBoss container and hit the servlet to see the result.
Fig 1: Test your sample API

Note: To see the admin console, JBoss Default Port is 9990 but to view the application the default port is 8080. So you will be able to see the API when you hit localhost:8080/context-root/API_URL
Note: The location of server.log file is JBOSS_HOME/standalone/log/server.log.


If you have any query or suggestion then kindly comment or mail us at sgaem.blog02@gmail.com


Hope it will help you guys !!
Thanks and Happy Learning.

7 comments:

  1. Anika Tech SupportJuly 21, 2019 at 6:17 PM

    office 365 business services
    WELCOME TO ANIKA TECH SUPPORT
    Anika Tech Support managed by a team of professionals utilising a combined 20+ years of experience in IT support and Managed IT services Focusing on Proactive support, continuity, growth and development. We are a forward thinking IT Company who support public and private sector using the latest tech as a driving force for our client’s Success.

    ReplyDelete
  2. I am unable to access service ,following error is shown
    RESTEASY003210: Could not find resource for full path: http://127.0.0.1:8080/api/hello

    ReplyDelete
  3. Hey , can we develop project with AEM and Spring Boot ?

    ReplyDelete
  4. you save me. Thanks

    ReplyDelete
  5. First of all thanks for postiing this blog.

    I am not able to my spring boot app logs neither jboss console nor in server.log. can you please help here?

    ReplyDelete