java在创建文件在weblogin_SpringBoot部署在Weblogic步骤详情

SpringBoot部署在Weblogic步骤详情

SpringBoot项目的pom.xml文件

添加web.xml和weblogic.xml文件

项目启动类:DemoApplication.java

部署项目到weblogic

系统测试

SpringBoot版本:2.0.1.RELEASE

WebLogic版本:Weblogic 12c

本文为测试SpringBoot项目部署在Weblogic服务器上的测试项目。不牵扯到任何的业务逻辑。可以直接将本文重点标注的几个点移至您现有的项目。

SpringBoot项目的pom.xml文件

其中需要添加的依赖为:

org.springframework.boot

spring-boot-legacy

2.0.0.RELEASE

org.springframework.boot

spring-boot-starter-tomcat

provided

打成war包文件:war

完整文件如下:

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0modelVersion>

org.springframework.bootgroupId>

spring-boot-starter-parentartifactId>

2.0.1.RELEASEversion>

parent>

com.examplegroupId>

demoartifactId>

0.0.1-SNAPSHOTversion>

demoname>

Springboot project run on weblogic.description>

warpackaging>

1.8java.version>

properties>

org.springframework.bootgroupId>

spring-boot-starterartifactId>

dependency>

org.springframework.bootgroupId>

spring-boot-starter-webartifactId>

dependency>

org.springframework.bootgroupId>

spring-boot-legacyartifactId>

2.0.0.RELEASEversion>

dependency>

org.springframework.bootgroupId>

spring-boot-starter-tomcatartifactId>

providedscope>

dependency>

dependencies>

org.springframework.bootgroupId>

spring-boot-maven-pluginartifactId>

plugin>

plugins>

build>

project>

添加web.xml和weblogic.xml文件

在main目录下创建webapp目录,和java、resources同级。

在webapp目录下添加WEB-INF目录,在WEB-INF目录下创建web.xml和weblogic.xml文件。

web.xml和weblogic.xml文件内容如下:

web.xml,其中com.example.demo.DemoApplication为你项目的启动类文件的目录。

contextConfigLocationparam-name>

com.example.demo.DemoApplicationparam-value>

context-param>

org.springframework.boot.legacy.context.web.SpringBootContextLoaderListenerlistener-class>

listener>

appServletservlet-name>

org.springframework.web.servlet.DispatcherServletservlet-class>

contextAttributeparam-name>

org.springframework.web.context.WebApplicationContext.ROOTparam-value>

init-param>

1load-on-startup>

servlet>

appServletservlet-name>

/url-pattern>

servlet-mapping>

web-app>

weblogic.xml,其中/demo为项目启动后的访问路径。如果不需要,直接改为/即可

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

org.slf4jpackage-name>

javax.validation.*package-name>

org.hibernate.*package-name>

javax.el.*package-name>

org.springframework.*package-name>

prefer-application-packages>

container-descriptor>

/democontext-root>

weblogic-web-app>

项目启动类:DemoApplication.java

注意将启动类继承SpringBootServletInitializer, 实现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";

}

}

以上项目配置完成,执行mvn clean package打成war文件。可以直接使用idea的maven打包。

部署项目到weblogic

详细步骤如下图:

4864574c51a0b8f1ed9e0309f4e03423.png

326229d5034c0aed4044c9e3bc0de7ff.png

2d856f61c2a18ce42ae8332a99963969.png

051b7bea3737fa1eed543e3e44953994.png

0d7c69c55ec199b40f953830156e5fe0.png

09e0be18d592c04807f9d159e28abb75.png

显示部署成功后,在浏览器输入地址访问:http://192.168.2.10:7001/demo/test

系统测试

显示结果如下图:

e2217560e14747804db4facbb143c870.png

本文到此结束了,后续文章会陆续更新,文档会同步在CSDN和GitHub保持同步更新。

点个关注再走呗~~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值