美文网首页
项目部署

项目部署

作者: 林深雾雨 | 来源:发表于2019-11-25 16:11 被阅读0次

项目打包方式:

工程需要打成war包

①打包方式改成war 指定打包方式 ②将自带的tomcat移除 在打包的时候不要打进去
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>

            <!-- 在整个依赖中排除以下(spring-boot-starter-tomcat)的依赖 将自带的tomcat剔除 -->
            <!-- 在开发和测试的时候不要排除 在打包的时候排除 -->
            <!-- 
            <exclusions> 
                <exclusion> 
                    <groupId>org.springframework.boot</groupId> 
                    <artifactId>spring-boot-starter-tomcat</artifactId> 
                </exclusion> 
            </exclusions> 
            -->
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <!-- provided 意思是打包的时候不用    在打war的时候写上 表示不打进去-->
            <scope>provided</scope>
            
            <!-- 在打jar的包时需要把内置的tomcat打到包里去  不写provide意思就是把tomcat打上-->
            <!-- <scope>provided</scope> -->
        </dependency>
③创建一个新的类
package com.example.demo;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer{

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        // TODO Auto-generated method stub
        return builder.sources(DemoApplication.class);
    }
}

④执行maven命令 ⑤放入tomcat运行

工程需要打成war包

①打包方式改成jar
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <!-- 1設置打包方式爲war -->
    <!-- <packaging>war</packaging> -->
    
    <!-- 1設置打包方式爲jar -->
    <packaging>jar</packaging>

②要把tmcat加入到项目中

<dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-web</artifactId>

           <!-- 在整个依赖中排除以下(spring-boot-starter-tomcat)的依赖 将自带的tomcat剔除 -->
           <!-- 在开发和测试的时候不要排除 在打包的时候排除 -->
           <!-- 
           <exclusions> 
               <exclusion> 
                   <groupId>org.springframework.boot</groupId> 
                   <artifactId>spring-boot-starter-tomcat</artifactId> 
               </exclusion> 
           </exclusions> 
           -->
       </dependency>

       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-tomcat</artifactId>
           <!-- provided 意思是打包的时候不用    在打war的时候写上 表示不打进去-->
           <!-- <scope>provided</scope> -->
           
           <!-- 在打jar的包时需要把内置的tomcat打到包里去  不写provide意思就是把tomcat打上-->
           <!-- <scope>provided</scope> --> 
       </dependency>

(纯前后端分离的项目)工程打成jar包(但是不能访问jsp文件)
使用内嵌的tomcat 不能移除
打包方式改成war 当由异常的时候要看日志 因为是内嵌Tomcat 所以要自己配置存放异常的日志文件位置

相关文章

网友评论

      本文标题:项目部署

      本文链接:https://www.haomeiwen.com/subject/imirictx.html