Spring Boot 部署到weblogic 12c

时间:2021-10-01 20:26:49

gradle:

buildscript {
    ext {
        springBootVersion = '1.5.3.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

version = ''
sourceCompatibility = 1.7

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}

 

DemooApplication.class:
package com.example;

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

@SpringBootApplication
public class DemooApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(DemooApplication.class);
    }
    public static void main(String[] args) {
        SpringApplication.run(DemooApplication.class, args);
    }
}

 

然后刷新gradle,构建一次,会发现项目下会自动新建一个文件夹:webapp 是个有蓝点图标的文件夹如下图,然后在文件夹下 新建:weblogic.xml

Spring Boot 部署到weblogic 12c

weblogic.xml:

<?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/ejb-jar_3_0.xsd
        http://xmlns.oracle.com/weblogic/weblogic-web-app
        http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4j</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
     <wls:context-root>/demoo</wls:context-root>
</wls:weblogic-web-app>

构建、部署即可,springboot基于servlet3.0 , weblogic 11g不支持servlet3.0,所以在weblogic11g上不能用(或许有其他办法吧)

参考链接:http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html