springboot+gradle/maven项目部署到外部tomcat

请使用tomcat8以上的版本

1.修改gradle文件
这边是gradle3.3

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        //gradle脚本需要使用的资源
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE")
    }
}

repositories {
    mavenCentral()
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'


sourceCompatibility = 1.8
targetCompatibility = 1.8


dependencies {
    // web 和 test
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile("org.springframework.boot:spring-boot-starter-test")
    // 设置内嵌tomcat
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    // spring boot:run
    runtime('org.springframework.boot:spring-boot-devtools')
    // mysql8需要高版本的
    compile('mysql:mysql-connector-java:5.1.46')
    // mybatis
    compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.1')
    // fastjson
    compile('com.alibaba:fastjson:1.2.5')

}

主要是加这两个

//内置的tomcat设置为provided
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
//通过bootRun启动而不是run application
runtime('org.springframework.boot:spring-boot-devtools')

2.修改application

@SpringBootApplication
@MapperScan("org.cth.gmweb.mapper")
public class GmwebApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(GmwebApplication.class);
    }

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

}

3.操作
application.properties中是这样的:

server.port=8088

使用bootRun启动项目,测试(localhost:8088/test)
使用war打包,在项目build\libs下找到war包,放置在tomcat的webapps目录下,启动tomcat,测试(ip:8088/项目名/test)

在这里插入图片描述

-----------------------19-06-23-------------------------
maven项目:
1.修改application 同上
2.修改pom文件

<packaging>war</packaging>
...
<!-- 内部tomcat-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值