栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot war包部署到Tomcat服务器

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot war包部署到Tomcat服务器

(1)pom.xml文件修改war,默认是jar包,节点中增加springboot,即生成war包的名字,完整pom.xml文件内容如下:



  4.0.0

  springboot
  springboot
  0.0.1-SNAPSHOT
  war

  springboot
  Demo project for Spring Boot

  
    org.springframework.boot
    spring-boot-starter-parent
    1.5.4.RELEASE
     
  

  
    UTF-8
    UTF-8
    1.7
  

  
    
      org.springframework.boot
      spring-boot-starter
      
 
   org.springframework.boot
   spring-boot-starter-logging
 
      
    
    
      org.springframework.boot
      spring-boot-starter-web
    
    
      org.springframework.boot
      spring-boot-starter-test
      test
    
    
      org.springframework.boot
      spring-boot-starter-thymeleaf
    
    
      org.springframework.boot
      spring-boot-starter-log4j
      1.3.8.RELEASE
    
    
      org.springframework.boot
      spring-boot-starter-data-redis
    
    
      mysql
      mysql-connector-java
    
    
      org.mybatis.spring.boot
      mybatis-spring-boot-starter
      1.1.1
    
  

  
    springboot
    
      
 org.springframework.boot
 spring-boot-maven-plugin
      
    
  

(2)修改项目启动类,继承SpringBootServletInitializer,如下:

package springboot;
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.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
@EnableCaching
public class SpringbootApplication extends SpringBootServletInitializer{

  public static void main(String[] args) {
    SpringApplication.run(SpringbootApplication.class, args);
  }
  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(SpringbootApplication.class);
  }
}

(3)打包:可以通过eclipse run as ->maven install,也可以进入项目的根目录,也就是pom.xml同一级目录,启动cmd控制台,执行mvn install package,如下:

(4)环境搭建(linux环境JDK安装与Tomacat安装(springboot支持tomcat7以上))

JDK安装参考:https://www.jb51.net/LINUXjishu/66536.html

Tomcat安装参考:https://www.jb51.net/article/95272.htm

(5)将打包好的war包上传至tomcat目录下webapp目录下,启动tomcat服务器。

(6)访问项目路径:http://ip地址:端口号/项目打包名称/方法名(项目打包名称即pom.xml中的的值)

(7)设置tomcat开机自动启动

  (1)修改脚本文件rc.local:vim /etc/rc.d/rc.local

  (2)在rc.local中增加:export JAVA_HOME = jdk安装路径 ,tomcat安装路径/bin/startup.sh start

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/141277.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号