SpringBoot项目部署到WebLogic

最近公司需要把springboot的项目发布到weblogic上去运行,其中搞出很多问题,现在把解决方案记录一下。

修改SpringBoot启动类

主要是继承extends SpringBootServletInitializer 类,实现 WebApplicationInitializer接口,重写方法protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)

package com.dowhere.webtest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.web.WebApplicationInitializer;

@SpringBootApplication
public class WebtestApplication extends SpringBootServletInitializer implements WebApplicationInitializer {


    /**
     * 重写方法configure
     * @param builder
     * @return
     */
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(WebtestApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(WebtestApplication.class, args);
    }

}

修改pom文件

修改打包方式war,同时添加tomcat的支持


<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.2.4.RELEASEversion>
        <relativePath/> 
    parent>
    <groupId>com.dowheregroupId>
    <artifactId>webtestartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <name>webtestname>
    <description>Demo project for Spring Bootdescription>
    <packaging>warpackaging>
    <properties>
        <java.version>1.8java.version>
    properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.bootgroupId>
                    <artifactId>spring-boot-starter-tomcatartifactId>
                exclusion>
            exclusions>
        dependency>


        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-tomcatartifactId>
            <scope>providedscope>
        dependency>


        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>
    dependencies>

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

project>

使用Logback

如果在项目中使用了Logback,需要告诉WebLogic打包版本,而不是服务器预先安装的版本。
可以通过添加WEB-INF/weblogic.xml具有内容如下:


<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
        https://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd
        http://xmlns.oracle.com/weblogic/weblogic-web-app
        https://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4jwls:package-name>
        wls:prefer-application-packages>
    wls:container-descriptor>
wls:weblogic-web-app>

你可能感兴趣的:(java,Spring)