项目作者: NajeebArif

项目描述 :
A Spring Boot REST App which runs on Weblogic 14c or 12c
高级语言: Java
项目地址: git://github.com/NajeebArif/Spring-Boot-On-Weblogic.git
创建时间: 2020-04-04T16:21:06Z
项目社区:https://github.com/NajeebArif/Spring-Boot-On-Weblogic

开源协议:

下载


Spring Boot On Weblogic

A Spring Boot 2.x REST App which runs on Weblogic 12c or Weblogic 14c

Running Spring Boot Application on Weblogic 14c and Weblogic 12c

If you are here, then that means you are already familiar with benefits of Spring Boot and you want to leverage these benefits in your next Application which will be deployed on Weblogic Server.

So without wasting much let’s get started with how to do that.

First thing we will do is that, when we run the spring initializer we will select the default packaging mode as WAR. I have used spring website because I am using IntelliJ Community Edition. You can use STS or intelliJ Ultimate Edition for the same.

Once the skeleton project is created you will see a servlet initializer config class created for you.

This class extends the SpringBootServletInitializer class and overrides the configure method. All the codes are auto generated for you and digging into the details of this class is indeed a concern for another topic.

Now we will have to add two xml files inside folder: main -> webapp -> WEB-INF. Spring creates resources folder for you but you will have to manually add webapp folder adjacent to resources and WEB-INF goes inside webapp folder.

Let’s create our two xml files inside WEB-INF folder:
1) weblogic.xml
2) disparcherServlet-servlet.xml

We will just add the root bean tag in the dispatcher servlet xml file and will leave it empty.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd">
  6. </beans>

The main part is the weblogic.xml. We will define the context root path here and the most important part prefer-application-packages tag:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app
  5. http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd">
  6. <context-root>/narif/poc/echo</context-root>
  7. <session-descriptor>
  8. <cookies-enabled>false</cookies-enabled>
  9. </session-descriptor>
  10. <container-descriptor>
  11. <prefer-application-packages>
  12. <package-name>org.slf4j</package-name>
  13. <package-name>com.fasterxml</package-name>
  14. <package-name>org.springframework</package-name>
  15. <package-name>org.apache.logging</package-name>
  16. <package-name>org.apache</package-name>
  17. </prefer-application-packages>
  18. </container-descriptor>
  19. </weblogic-web-app>

These are the bare minimum stuffs you will need to deploy a spring boot war on weblogic. After completing the above steps you can do a dry run.

So run mvn package and deploy the war file on weblogic.

Build phase:

Deployment phase:

Now let’s create a very simple ping service which will respond with “pong”.

  1. package narif.poc.wlseries.echorestapi;
  2. import org.springframework.web.bind.annotation.GetMapping;
  3. import org.springframework.web.bind.annotation.RestController;
  4. @RestController
  5. public class EchoRestService {
  6. @GetMapping("ping")
  7. public String ping(){
  8. return "pong";
  9. }
  10. }

Again build and ship to wls and try this url in postman.

• NOTE:
• I have used Spring Boot 2.2.6
• I have tested on Weblogic 12c and Weblogic 14c.