• springboot 使用外置tomcat启动197


    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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.8.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
    
        <groupId>com.ds</groupId>
        <artifactId>ksh</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>ksh</name>
        <packaging>war</packaging>
        <description>Demo project for Spring Boot</description>
    
        <properties>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <!--web全栈开发-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <!--使用外部tomcat需要把内置的tomcat排除-->
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    
            <dependency>
                <!--添加springboot-tomcat scope必须时 provided-->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>
    
            <!--测试 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <!--使用freemarker必须包-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-freemarker</artifactId>
            </dependency>
    
            <!--java与mysql连接的jar包驱动程序-->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.1.6</version>
            </dependency>
    
            <!-- mybatis-->
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>1.3.1</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
    
            <!-- jdbcTemplate -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
            </dependency>
    
            <!-- redis -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
            </dependency>
    
            <!--json格式化-->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.41</version>
            </dependency>
    
        </dependencies>
    
        <build>
            <finalName>ksh_gis</finalName>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
            </plugins>
            <!--        分离配置文件-->
            <!--     <resources>
                     <resource>
                         <directory>src/main/resources</directory>
                         <excludes>
                             <exclude>**/*.properties</exclude>
                             <exclude>**/*.yml</exclude>
                         </excludes>
                     </resource>
                 </resources>-->
        </build>
    
    </project>

    启动类

    package com.ds.ksh.v1;
    
    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;
    
    /*@SpringBootApplication
    @MapperScan(basePackages = "com.ds")
    public class KshApplication {
        public static void main(String[] args) {
            SpringApplication.run(KshApplication.class, args);
        }
    }*/
    @SpringBootApplication
    public class KshApplication extends SpringBootServletInitializer {
    
    
        public static void main(String[] args) {
            SpringApplication.run(KshApplication.class, args);
        }
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(KshApplication.class);
        }
    }
    

      tomcat部署   tomcat7使用以上版本不然有时候启动肯有问题

    删除ROOT --> 将war复制到webapp下  -->  修改项目名字为ROOT.war 

    这样的好处是不用再配置别的东西直接启动就能访问

  • 相关阅读:
    PHP 判断数据类型
    JavaScript学习总结(六)——JavaScript判断数据类型总结
    JavaScript学习总结(五)——Javascript中==和===的区别
    JavaScript学习总结(四)——逻辑OR运算符详解
    JavaScript学习总结(三)——逻辑And运算符详解
    JavaScript学习总结(二)——逻辑Not运算符详解
    JavaScript学习总结(一)——JavaScript基础
    JavaScript1.6数组新特性和JQuery的几个工具方法
    用jquery循环map
    php利用递归函数实现无限级分类
  • 原文地址:https://www.cnblogs.com/Ai-Hen-Jiao-zhi/p/11685781.html
Copyright © 2020-2023  润新知