springboot应用部署到weblogic 基本步骤

  • Post author:
  • Post category:其他




1、在原pom.xml的基础上增添leagcy依赖,并修改打包方式为war

<artifactId>liqi-admin</artifactId>
<packaging>war</packaging>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-legacy</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>



2、去掉spring boot依赖自带的tomcat,使用外置tomcat,若有servlet-api的使用,则一起加入依赖

<!-- SpringBoot Web容器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- 加exclusions去除打包时的内置tomcat-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>tomcat-embed-el</groupId>
<artifactId>org.apache.tomcat.embed</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--增加servlet依赖根据需要选择2.5或者3.0-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<!-- <scope>test</scope>-->
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<!-- <scope>provided</scope>-->
</dependency>
<!-- 上下任选其一 -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>8.5.23</version>
<!-- <scope>provided</scope>-->
</dependency>



3、修改Springboot启动类 增加extends SpringBootServletInitializer implements WebApplicationInitializer

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@ComponentScan(basePackages = "com.liqi")
public class LiQiApplication extends SpringBootServletInitializer implements WebApplicationInitializer
{
    public static void main(String[] args)
    {
        SpringApplication.run(LiQiApplication.class, args);
        System.out.println("(♥◠‿◠)ノ゙  LIQI程序启动成功!   ლ(´ڡ`ლ)゙  \n");
    }
}

启动类同级package增加一个配置类

在这里插入图片描述

public class SpringBootStartApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
        return builder.sources(LiQiApplication.class);
    }
}



4、使用IDEA增加web.xml和weblogic.xml文件

选中模块按F4,如图分别点击“+”和 add application server spcific descriptor增添web.xml和weblogic.xml

在这里插入图片描述

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://xmlns.oracle.com/weblogic/weblogic-web-app
http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.3</wls:weblogic-version>
<wls:context-root>/</wls:context-root>  <!-- 这里根据实际需求修改为自己部署后所需启动路径,这里是使用根路径-->
<wls:container-descriptor>
<!-- <wls:prefer-application-packages>-->
<!-- <wls:package-name>org.slf4j.*</wls:package-name>-->
<!-- <wls:package-name>org.springframework.*</wls:package-name>-->
<!-- <wls:package-name>javax.validation.*</wls:package-name>-->
<!-- </wls:prefer-application-packages>-->
<!-- <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>-->
<wls:prefer-application-packages>
<wls:package-name>org.springframework.*</wls:package-name>
<wls:package-name>org.hibernate.*</wls:package-name>
<wls:package-name>javax.validation.*</wls:package-name>
<wls:package-name>javax.validation.spi.*</wls:package-name>
<wls:package-name>org.slf4j.*</wls:package-name>
</wls:prefer-application-packages>
<wls:show-archived-real-path-enabled>true</wls:show-archived-real-path-enabled>
</wls:container-descriptor>
</wls:weblogic-web-app>

使用package-name标签指定特定的包优先使用应用自带jar,而不是weblogic的lib库

web.xml文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         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_2_5.xsd">

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>com.liqi.admin.LiQiApplication</param-value> <!-- 填写springboot启动类的全路径 -->
</context-param>

    <listener>
        <!--        <listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>-->
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <filter>
        <filter-name>metricFilter</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>metricFilter</filter-name>
        <url-pattern> /* </url-pattern> 
    </filter-mapping>

    <!--增加shiro权限控制过滤器-->

    <filter>
        <filter-name>shiroFilter</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        <init-param>
            <param-name>targetFilterLifecycle</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>shiroFilter</filter-name>
        <url-pattern>/*</url-pattern>  
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>

    <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>



5、 增加打包插件到pom.xml

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<attachClasses>true</attachClasses>
<archive>
<manifestEntries>
<Weblogic-Application-Version>${project.version}</Weblogic-Application-Version>
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
<addClasspath>lib/</addClasspath>
</manifest>
</archive>
<!-- <webResources>-->
<!-- <resource>-->
<!-- <directory>${project.basedir}/src/main/resources/static</directory>-->
<!-- </resource>-->
<!-- </webResources>-->
<warName>${project.artifactId}</warName>
</configuration>
</plugin>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- <version>2.1.1.RELEASE</version>-->
<configuration>
<classifier>BOOT</classifier>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>



6、构建war包

在这里插入图片描述

在这里插入图片描述



7、通过weblogic控制台部署war包,完成后通过127.0.0.1:7001打开应用首页,成功打开即完成部署

在这里插入图片描述



8、注意点

(1)以上配置仅是对于我所部署项目的设置,你需要根据自己项目的实际情况酌情修改,如web.xml,标准是如文章所写,但我这么写会报错

weblogic Cannot initialize context because there is already a root application context present,后面把所有内容注释就可以正常运行了。

(2) weblogic一般package-name标签仅需要包含

” wls:package-nameorg.slf4j.

</wls:package-name>”

“wls:package-nameorg.springframework.

</wls:package-name>”

其他需要的包也根据项目需要增添,如 wls:package-nameorg.hibernate.*</wls:package-name>等。

参考链接:

如何优雅的在weblogic上部署spring-boot



记一次将spring-boot应用发布到weblogic的步骤以及遇到的问题



weblogic部署springboot项目war包



springboot2里运行weblogic11g



版权声明:本文为popuui123原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。