I've been intending to write about this topic for a while, but I always end up putting it off. So I thought it was time, after listening a podcast where it encourages talking about a subject, even though there are thousands of threads about it.
Where I work, before we start our migration to the cloud, we made a lot of use of WebSphere Application Server. There were our more than 200 applications, from old back offices to services for partners.
For a long time "WebSphere" was our great friend and our biggest villain.
Making application development easy was always our goal, and for this reason, we made use of the Spring Boot Framework in our Java applications, but to publish them to WebSphere it was necessary to make a set of configurations that we can only find through research and testing.
So the goal here is show the step by step to create a Spring Boot application and publish it to WebSphere.
Create the application
To publish a Spring Boot application, we're going to create it directly through spring initialzr.
Just generate an application using Java 8, and add Spring Web, Lombok and Spring Security dependencies.
We’re going to make use of a web container, we don’t need Spring Boot to generate a fat jar, so, choose packagin war.
Many times, in the examples, they were always using only the Spring Web and I always wondered whether or not there were compatibility issues.
With our application generated, we will follow the step by step for its publication.
Click on WebSphere enterprise application
Click on Install
So far we've taken advantage of everything that WebSphere makes it easy for us, we don't need to detail the entire installation to publish our application.
Now we will actually start configuring our application, in Step 1 just choose the name of your application.
In Step 2 we will select the server that the application will run. The important thing is that it contains the Java 8 that you selected when generating the application.
In Step 3 we will select the host.
In Step 4 we will define the context root to access the application. Choose a name that is not being used.
In Step 5, set the option to true so that your application’s metadata can be generated and persisted.
Finally, review and publish your application.
You have published the application, but as you can see, trying to launch it will not work.
Now the configurations actually begin, in fact there aren’t many. The concept you need to understand is that WebSphere has a set of libraries, that if loaded in the wrong sequence will not allow your application to start successfully.
For that, just change the class loading, so far a simple task.
Select the Classes loaded with local class loader first (parent last) option. This option causes the class loader to attempt to load classes from its local class path before delegating the class loading to its parent. Using this policy, an application class loader can override and provide its own version of a class that exists in the parent class loader.
What worked for us was modifying the module class loader.
Select the Classes loaded with local class loader first (parent last) option for the module as well.
After these settings go back and try to start the application again, if everything goes correctly it will start without any problem.