springboot:deploy_springboot_2.3.1_on_weblogic_12c

Deploy SpringBoot 2 on Weblogic 12c

Deploying code on old container is a headache. Here is how I solve it. This example is based on SpringBoot 2.3.1.RELEASE, but should work on other 2.x version.

  1. We need to have the following xml config in those files.
  2. !!!The MS SQL driver sqljdbc42.jar would no longer work with new Hibernate 5, so you need to update to at least version 6.3.2 (6.4.0.jre8 recommended) on your WebLogic server!!!.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>SNAPSHOT</version>
    <packaging>war</packaging>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>logback-classic</artifactId>
                    <groupId>ch.qos.logback</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>log4j-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>


        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>6.4.0.jre8</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.30</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

This file located at ./src/main/resources/log4j.xml. You might un-comment the logger in this file if needed.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="Console"
              class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <!-- l, L, M - is extremely slow. It's use should be avoided unless execution
                speed is not an issue. -->
            <param name="ConversionPattern"
                   value="%p: %d{dd.MM.yyyy HH:mm:ss.SSS} %l %n    %m%n"/>
        </layout>
    </appender>

    <appender name="File"
              class="org.apache.log4j.DailyRollingFileAppender">
        <param name="Encoding" value="UTF-8"/>
        <param name="File" value="logs/trace.log"/>
        <param name="Append" value="true"/>
        <layout class="org.apache.log4j.PatternLayout">
            <!-- l, L, M - is extremely slow. It's use should be avoided unless execution
                speed is not an issue. -->
            <param name="ConversionPattern"
                   value="%p: %d{dd.MM.yyyy HH:mm:ss.SSS} %l %n    %m%n"/>
        </layout>
    </appender>

<!--    &lt;!&ndash; Application Loggers &ndash;&gt;-->
<!--    <logger name="com.journaldev.spring">-->
<!--        <level value="info"/>-->
<!--    </logger>-->

<!--    &lt;!&ndash; 3rdparty Loggers &ndash;&gt;-->
<!--    <logger name="org.springframework.core">-->
<!--        <level value="info"/>-->
<!--    </logger>-->

<!--    <logger name="org.hibernate">-->
<!--        <level value="info"/>-->
<!--    </logger>-->

<!--    <logger name="org.springframework.beans">-->
<!--        <level value="info"/>-->
<!--    </logger>-->

<!--    <logger name="org.springframework.context">-->
<!--        <level value="info"/>-->
<!--    </logger>-->

<!--    <logger name="org.springframework.web">-->
<!--        <level value="info"/>-->
<!--    </logger>-->

    <!-- The root category is used for all loggers unless a more specific logger
        matches. If none of the loggers are assigned a level, then all loggers inherit
        the level of the root logger which is set to DEBUG by default -->
    <root>
        <level value="warn"/>
        <appender-ref ref="Console"/>
        <!-- <appender-ref ref="File" /> -->
    </root>

</log4j:configuration>

This file located at /src/main/webapp/WEB-INF/weblogic.xml.

<wls:context-root>demo</wls:context-root> is the path of the URI of your application, you might want to change it to something else.

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
        xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.9/weblogic-web-app.xsd">

    <wls:context-root>demo</wls:context-root>

    <wls:weblogic-version>12.2.1.2</wls:weblogic-version>
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4j.*</wls:package-name>
            <wls:package-name>org.apache.commons.*</wls:package-name>
            <wls:package-name>org.springframework.*</wls:package-name>
            <wls:package-name>org.hibernate.annotations.common.*</wls:package-name>
            <wls:package-name>com.fasterxml.*</wls:package-name>
        </wls:prefer-application-packages>

        <wls:prefer-application-resources>
            <wls:resource-name>org/slf4j/impl/StaticLoggerBinder.class</wls:resource-name>
        </wls:prefer-application-resources>

    </wls:container-descriptor>
</wls:weblogic-web-app>
  • springboot/deploy_springboot_2.3.1_on_weblogic_12c.txt
  • Last modified: 2020/11/02 11:24
  • by chongtin