Migrating from Weblogic to Spring Boot — Part 1

We all have existing applications running on Weblogic servers and want to replace them with the Spring Boot Application. This article express how to migrate a Weblogic application’s data sources to Spring Boot and how to create contract first SOAP web services in Spring Boot which will have same contract with old ones deploy in Weblogic. In addition, I will also describe deploying a Spring Boot app on a server managed by Weblogic as a bonus.

1. Define the Weblogic Datasource on Spring Boot

1.1 First, add the following dependency to the pom

1.2 The details and credentials of the data source should be placed in the application.properties file in your resource directory.

1.3 Next, create a configuration class. This class allows you to set up data source and create the jdbcTemplate.

Finally, you can inject the jdbcTemplate where you require it.

1.4. User/Password Encryption!!!

The password must not be clearly visible in the property file and therefore it must be encrypted. That’s so easy to do using the Jasypt library.

First of all, you must encrypt your password using the Jasypt maven plugin below.

1.5 Add the following plugin to the pom.

1.6 Perform the following command.

1.7 Next, add the following dependency to the pom.

1.8 The encrypted password must be written in ENC(), so overwrite the pass in the properties file as below.

Now, once Jasypt sees the ENC keyword, it will decrypt and provide the password to the beans.

1.9 Jasypt uses PBEWITHMD5ANDDES encryption algorithm as a default. Various algorithms can be used. Certain algorithms are not supplied by default. So we need third-party suppliers. Add the dependency below to your pom.

1.10 Next, add BouncyCastleProvider in your any bean class.

1.11 Java version should be higher than Java 11 otherwise you need to update the two security jar files.

jdk1.X.XXX/jre/lib/security

Download URL : https://www.oracle.com/java/technologies/javase-jce8-downloads.html

1.12 Lastly, give your salt and algorithm in the JVM parameters on start-up.

-Djasypt.encryptor.password=<your salt string>-Djasypt.encryptor.algorithm=<your algorithm>

3. Contract-First Web Services on Spring Boot

Contract last means you start with the code, and let the contract be generated from that.

Contract first means, you create the contract first, and you implement according to this contract.

PS : XSD,WSDL, WSDD etc. are your contract.

If you have an existing service with several integrated clients, you must keep the same contract after the technological change. For instance, you may encounter this by replacing EJB stateless soap services with spring soap services.

Let’s look how to do that;

3.1 Add the following plugin to the pom.

  • ${project.basedir}/src/main/resources ~ The location of the XSD file
  • ${project.basedir}/src/main/java ~ The Java code to be generated to

3.2 Perform the following command.

mvn compile

The classes will be generated automatically after Maven build.

For more information, check out the Baeldung example.

4. Deployment of the Spring Boot application on a Weblogic server

<packaging>war</packaging>

4.2 Change the scope of Tomcat dependency as provided.

4.3 Replace the Spring Boot package build plugin with the Maven war plugin as below.

4.4 Put the web.xml file and weblogic.xml file into the WEB-INF folder.

4.5 Update the main class of the application to extend SpringBootServletInitializer(override its config method) and to implement WebApplicationInitializer if you use web.

I highly recommend reading the second part of this article.

I hope you found my post useful. Feel free to leave a comment and ask your questions. see you in my next post :)

Software Developer | Good Maker | Cyclist&Sport Club Manager | Portrait Artist