Deploying Spring Boot with Jersey on WebLogic

15 minutes read

Why would you ever want to have your Spring Boot application deployed on a Java Enterprise Application Server like WebLogic? The reasons may vary but usually, they all go under that scope of some corporate requirements. For example, there already might be a standardized system for software development with tools to which you must adapt. But is it possible to run Spring on an application server? And what's this whole JAX-RS thing that Java EE offers? How do I even bite this? Let's do this in small steps on the example of Spring Boot 2, WebLogic and Jersey 1.x/2.x.

From an Embedded Web Server (JAR) to a Web Application (WAR)

Spring Boot applications are usually built into jars with embedded web servers. This is done thanks to the starter dependencies. For example, the primary web starter spring-boot-starter-web by default includes 'spring-boot-starter-tomcat' which in turn includes tomcat-embed-core. Of course, Tomcat is not the only viable option for choosing an embedded web server. Spring Boot also provides other starters like Jetty spring-boot-starter-jetty and Undertow spring-boot-starter-undertow.

<!-- Usual initial configuration -->
        <!-- Exclude the Tomcat dependency if you decide to use a different Web Server -->
<!-- For an example, you can use Jetty instead -->

The first step on the road to the Application Server is to remove the embedded web server from the JAR and switch to WAR packaging. With web application archive (WAR) we will be able to deploy our web application not only on an application server (WebLogic) but also on a dedicated web server (Tomcat). This is quite easy and requires switching from <packaging>jar</packaging> to <packaging>war</packaging>.

Secondly, we have to switch the web server starter dependency from the default compile scope to provided. This way the relevant classes will not be packaged into the WAR, as we will expect the container to provide necessary dependencies at the runtime.

<!-- Replace spring-boot-starter-tomcat with chosen web server starter and set the scope to provided -->

Ok, but aren't we missing something? With the JAR method, we specified the main method for the build package phase in the spring-boot-maven-plugin:


To load your Spring application configuration in the container environment, we have to set up the starting point equivalent of the main method (which will configure the dispatcher, filters, servlets and listeners). Keep in mind that this configuration is for Servlet API 3.1+ (Spring Boot 2 + WLS 12.2.1). For legacy versions, spring-boot-legacy might be helpful.

Back to the topic – we have to extend SpringBootServletInitializer and provide our configuration sources. What's more, depending on the version, we might need to implement WebApplicationInitializer again, even though the SpringBootServletInitializer already implements it. Otherwise, WebLogic does not pick up this class. This is a bug that has been resolved in version 12.1.3 (patch 16769849). If you're curious, how the mechanism works – check out SpringServletContainerInitializer javadocs.

public class Application extends SpringBootServletInitializer implements WebApplicationInitializer {

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);

    public static void main(String[] args) {, args);


What's nice is that spring-boot-maven-plugin will also take care of packaging the WAR so you don't have to configure maven-war-plugin explicitly.

Jersey on the WebLogic

Application servers have to comply with JEE specs. Since 12.2.1 is JEE7 certified, WebLogic provides support for Jersey 2.x (JAX-RS 2.0 RI) through explicit registration of a shared library. Version provides this support out-of-the-box. The Jersey 1.x server-side APIs are no longer supported but the client packages are still maintained (though deprecated) for backward compatibility. As you can guess, this can get a bit complicated depending on the version of the application server.

In the case of WebLogic and other application servers, you have basically two options. Either comply with the libraries provided by the container or bring your own ones together with the application. The first choice is a valid solution when you start developing your application from scratch. Whereas, the second option is much less painful when your project is already using a set of defined and verified libraries.

To set up this, add a configuration file at src/main/webapp/WEB-INF/weblogic.xml. A sample configuration which prefers Jersey libraries packed with the application might look like this:

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls=""

            <!-- jsr311 -->
            <!-- javassist -->
            <!-- aop repackaged -->

            <!-- jersey 2 -->

            <!-- hk2 -->


            <!-- jersey -->

            <!-- hk2 -->


But to know which libraries should be preferred in our case some analysis must be done first, otherwise, we are prone to errors like java.lang.LinkageError, java.lang.NoClassDefFoundError and java.lang.ClassNotFoundException. We need to know which packages are provided by the application server and which come with our application. To detect and resolve such conflicts, Oracle provides the Classloader Analysis Tool (CAT). It's a web application that usually resides at %WL_HOME%/wlserver/server/lib/wls-cat.war. By default it is deployed at localhost:port/wls-cat, so you might want to check it first before deploying it manually using the console. A great reference on how to use this application and resolve conflicts is a guide on the Syscon Middleware blog.

It might be still quirky to get the prefer-application-resources right. It's generally used for defining service providers at /META-INF/services/. A typical error would say that the provider implementation could not be found:

weblogic.application.ModuleException: org.glassfish.jersey.internal.ServiceConfigurationError: org.glassfish.jersey.server.spi.ComponentProvider: The class org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider implementing the provider interface org.glassfish.jersey.server.spi.ComponentProvider is not found. The provider implementation is ignored.:org.glassfish.jersey.internal.ServiceConfigurationError:org.glassfish.jersey.server.spi.ComponentProvider: The class org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider implementing the provider interface org.glassfish.jersey.server.spi.ComponentProvider is not found. The provider implementation is ignored.
at org.glassfish.jersey.internal.ServiceFinder.access$300(
at org.glassfish.jersey.internal.ServiceFinder$LazyObjectIterator.handleClassNotFoundException(
at org.glassfish.jersey.internal.ServiceFinder$LazyObjectIterator.hasNext(
at org.glassfish.jersey.server.ApplicationHandler.getRankedComponentProviders(
Truncated. see log file for complete stacktrace


When deploying Spring application on an application server, the more dependencies you pull (JPA/Bean validation) the more conflicts you will have. It's a good idea to keep this in mind during development if you plan on deploying the WebLogic. Lastly, if you want to configure the context-path of your Spring Boot application deployed on the WebLogic, you can do so using mentioned before weblogic.xml configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls=""

This value will overwrite server.servlet.context-path value from src/main/resources/application.yml and the application will be server under correct path on the WebLogic.

Other quirks

There are a few quirks that you might or might not encounter. Knowing about them will save you some time finding out the solutions.


If you're migrating a complex Spring Boot REST app backed by Jersey, you might get the following error:

java.lang.IllegalArgumentException: interface org.glassfish.hk2.api.ProxyCtl is not visible from class loader

In such a case, it's a good idea to check whether @Context HttpServletRequest request is injected anywhere in your filters/services. There have been similar problems reported when using Jersey. One of the workarounds is to retrieve the HttpServletRequest from the ThreadLocal properties of RequestContextHolder:

((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();

Automatically registered Jersey

JAX-RS application resources can still be scanned by the WebLogic. This would be unfeasible if you're registering the servlet containers explicitly and programmatically in Spring Boot through ServletRegistrationBean. You might want to not have some or any of the resources scanned (or change the default mapping).

Automatically registered REST Service by WebLogic

To do this, just provide a parameter value (empty to disable) for jersey.config.server.provider.packages in src/main/webapp/WEB-INF/web.xml like so:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi=""
  version="3.0" metadata-complete="true">

There is a caveat that the web.xml version must be set to "3.0" or higher. Otherwise, the Spring bootstrapping might get ignored.


By implementing JEE specification, Application Servers differ vastly from simple Web Servers. Though the configuration is not trivial, It's still possible to convert a Spring Boot application run on an embedded server so that it's compatible with an application server such as WebLogic. The steps that are needed to be taken for such a migration are generally similar regardless of vendors, though the implementation may vary. For example, WildFly has jboss-deployment-structure.xml that serves a similar purpose as weblogic-application.xml (EAR level equivalent of weblogic.xml). More details on this topic can usually be found in the application server documentation under the "Class Loading" section.

The knowledge about class loading and JEE specification should give a good headstart for deploying more complex applications like Spring Cloud if such a requirement arises. By taking advantage of maven profiles, the embedded server configuration can still be kept for cross-testing and compatibility validation.