• SpringBoot war包部署到Tomcat服务器


    转载https://www.cnblogs.com/gdpuzxs/p/7224959.html

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

    复制代码
    <?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>springboot</groupId>
        <artifactId>springboot</artifactId>
        <version>0.0.1-SNAPSHOT</version>
       
       <packaging>war</packaging> <name>springboot</name>
    <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.7</java.version> </properties> <dependencies> ...... </dependencies> <build> <finalName>springboot</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
    复制代码

      (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以上))

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

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

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

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

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

  • 相关阅读:
    299. Bulls and Cows
    Canvas实现文字散粒子化
    jQuery触发a标签点击事件-为什么不跳转
    Java 理论与实践: 正确使用 Volatile 变量
    图片全屏背景 代码实例
    Canvas 唯美雨落代码实现
    开发过程中资源限制的挑战
    死锁
    如何减少并发编程中的上下文切换
    Cookie工具类
  • 原文地址:https://www.cnblogs.com/brxHqs/p/9628901.html
Copyright © 2020-2023  润新知