SpringBoot部署在Weblogic的操作步驟
SpringBoot版本:2.0.1.RELEASE
WebLogic版本:Weblogic 12c
本文為測試SpringBoot項(xiàng)目部署在Weblogic服務(wù)器上的測試項(xiàng)目。不牽扯到任何的業(yè)務(wù)邏輯??梢灾苯訉⒈疚闹攸c(diǎn)標(biāo)注的幾個(gè)點(diǎn)移至您現(xiàn)有的項(xiàng)目。
SpringBoot項(xiàng)目的pom.xml文件
其中需要添加的依賴為:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-legacy</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
打成war包文件:<packaging>war</packaging>
完整文件如下:
<?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.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Springboot project run on weblogic.</description>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 部署weblogic需要 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-legacy</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
添加web.xml和weblogic.xml文件
在main目錄下創(chuàng)建webapp目錄,和java、resources同級。
在webapp目錄下添加WEB-INF目錄,在WEB-INF目錄下創(chuàng)建web.xml和weblogic.xml文件。
web.xml和weblogic.xml文件內(nèi)容如下:
web.xml,其中com.example.demo.DemoApplication為你項(xiàng)目的啟動類文件的目錄。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.example.demo.DemoApplication</param-value>
</context-param>
<listener>
<listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextAttribute</param-name>
<param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
weblogic.xml,其中<context-root>/demo</context-root>為項(xiàng)目啟動后的訪問路徑。如果不需要,直接改為<context-root>/</context-root>即可
<?xml version='1.0' encoding='UTF-8'?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.3/weblogic-web-app.xsd">
<container-descriptor>
<prefer-application-packages>
<package-name>org.slf4j</package-name>
<package-name>javax.validation.*</package-name>
<package-name>org.hibernate.*</package-name>
<package-name>javax.el.*</package-name>
<package-name>org.springframework.*</package-name>
</prefer-application-packages>
</container-descriptor>
<context-root>/demo</context-root>
</weblogic-web-app>
項(xiàng)目啟動類:DemoApplication.java
注意將啟動類繼承SpringBootServletInitializer, 實(shí)現(xiàn)WebApplicationInitializer
package com.example.demo;
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;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/test")
public String test(){
return "test";
}
}
以上項(xiàng)目配置完成,執(zhí)行mvn clean package打成war文件。可以直接使用idea的maven打包。
部署項(xiàng)目到weblogic
詳細(xì)步驟如下圖:





顯示部署成功后,在瀏覽器輸入地址訪問:http://192.168.2.10:7001/demo/test
系統(tǒng)測試
顯示結(jié)果如下圖:

程序源碼
本文涉及到的項(xiàng)目源碼已經(jīng)push到github上,需要的小伙伴可以去拿一下。
如果項(xiàng)目一直部署不成功,建議小伙伴創(chuàng)建一個(gè)新的空項(xiàng)目,然后只放必須的pom依賴,放入weblogic的配置,打包試一下是否成功。
若使用本文的配置,建議使用全套呦,可能因?yàn)楹苄〉募?xì)節(jié)不一致,就會導(dǎo)致項(xiàng)目部署出錯(cuò)。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Spring 實(shí)現(xiàn)excel及pdf導(dǎo)出表格示例
本篇文章主要介紹了Spring 實(shí)現(xiàn)excel及pdf導(dǎo)出表格示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-03-03
SpringBoot讀取自定義配置文件方式(properties,yaml)
這篇文章主要介紹了SpringBoot讀取自定義配置文件方式(properties,yaml),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07
Java中的HashSet集合存儲數(shù)據(jù)的結(jié)構(gòu)詳解
這篇文章主要介紹了Java中的HashSet集合存儲數(shù)據(jù)的結(jié)構(gòu)詳解,數(shù)組結(jié)構(gòu)他把元素進(jìn)行分組,相同哈希值的元素是一組,鏈表/紅黑樹結(jié)構(gòu)把相同哈希值的元素鏈接到一起,存儲數(shù)據(jù)到集合中,先計(jì)算元素的哈希值,需要的朋友可以參考下2023-09-09
解決Maven parent.relativePath帶給我的坑
在Linux環(huán)境下使用Maven進(jìn)行項(xiàng)目打包時(shí),可能會遇到“當(dāng)前目錄沒有pom文件”的錯(cuò)誤,需要確認(rèn)在包含pom.xml文件的項(xiàng)目目錄下執(zhí)行Maven命令,另外,如果遇到“parent.relativePath points at wrong local POM”錯(cuò)誤,可能是父模塊依賴問題2024-09-09
SpringBootAdmin+actuator實(shí)現(xiàn)服務(wù)監(jiān)控
這篇文章主要為大家詳細(xì)介紹了SpringBootAdmin+actuator實(shí)現(xiàn)服務(wù)監(jiān)控,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01
java對象中什么時(shí)候適合用static修飾符踩坑解決記錄
這篇文章主要為大家介紹了java對象中什么時(shí)候適合用static修飾符踩坑解決記錄,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09
關(guān)于Gateway網(wǎng)關(guān)中配置跨域的三種方案
文章總結(jié):介紹了三種處理跨域請求的方法:在Controller類上添加注解、通過配置類實(shí)現(xiàn)重寫WebMvcConfigurer接口和在配置文件中統(tǒng)一設(shè)置,希望這些方法能幫助讀者解決跨域問題2024-11-11
利用Jackson實(shí)現(xiàn)數(shù)據(jù)脫敏的示例詳解
在我們的企業(yè)項(xiàng)目中,為了保護(hù)用戶隱私,數(shù)據(jù)脫敏成了必不可少的操作,那么我們怎么優(yōu)雅的利用Jackson實(shí)現(xiàn)數(shù)據(jù)脫敏呢,本文就來和大家詳細(xì)聊聊,希望對大家有所幫助2023-05-05
springmvc接收json串,轉(zhuǎn)換為實(shí)體類List方法
今天小編就為大家分享一篇springmvc接收json串,轉(zhuǎn)換為實(shí)體類List方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08

