如何在SpringBoot中创建WAR文件,而不使用父级和web.xml?

如何在SpringBoot中创建WAR文件,而不使用父级和web.xml?,spring,spring-boot,Spring,Spring Boot,在我的spring boot中,将我的旧J2EE项目转换为基于spring boot的项目,我使用: <dependencyManagement> <dependencies> <!--继承父POM中关于Spring的依赖项--> <dependency> <!-- Import dependency management from Spring Boot -->

在我的spring boot中,将我的旧J2EE项目转换为基于spring boot的项目,我使用:

 <dependencyManagement>
    <dependencies>
        <!--继承父POM中关于Spring的依赖项-->
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>${spring-boot-version}</version>
            <type>pom</type>
            <scope>import</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</dependencyManagement>

为什么使用不同的包装类型?只要在任何地方都使用相同的。你可以很好地运行一个嵌入防波堤的战争。。。另外,为不同的环境构建不同的工件通常是您不应该也不应该做的事情。基本上你现在正在部署一些未经测试的东西(因为你构建了一个新的工件)。哇,问题是当我使用父pom时,我不能使用资源过滤,当我不使用父pom时,我不能打包war。我知道,但你不应该使用不同的打包,因为Spring boot和war对jar的打包方式不同,这可能会混淆它。首先,我会开始修复不同的构建。
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>wx</groupId>
<artifactId>rarf</artifactId>
<packaging>${packaging-target}</packaging>
<version>0.2.0-SNAPSHOT</version>
<name>RARF Implementation</name>
<url>http://maven.apache.org</url>

<properties>
    <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
    <spring-boot-version>1.3.3.RELEASE</spring-boot-version>
</properties>


<build>
    <finalName>LiveForest</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.4.2</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>
                maven-project-info-reports-plugin
            </artifactId>
            <version>2.8</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.10</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>${spring-boot-main-class}</mainClass>
                <layout>ZIP</layout>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
            <filtering>true</filtering>
        </resource>
        <resource>
            <directory>src/main/webapp</directory>
            <includes>
                <include>**/*</include>
            </includes>
            <filtering>true</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.xml</include>
                <include>**/*.props</include>
                <include>**/*.properties</include>
            </includes>
            <filtering>true</filtering>
        </resource>
        <resource>
            <directory>./</directory>
            <includes>
                <include>config.properties</include>
            </includes>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

<dependencyManagement>
    <dependencies>
        <!--继承父POM中关于Spring的依赖项-->
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>${spring-boot-version}</version>
            <type>pom</type>
            <scope>import</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</dependencyManagement>


<dependencies>

    <!--Server-->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>

    <!--Spring-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
        <!--设置作用域为provider,防止与容器中的上下文冲突-->
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>4.2.2.RELEASE</version>
    </dependency>

    <!--Spring Test框架 -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>4.2.2.RELEASE</version>
    </dependency>


    <!--Libs-->
    <!--自己的庫,有大量的依賴從它這裡繼承而來-->
    <dependency>
        <groupId>com.github.wxyyxc1992</groupId>
        <artifactId>WXJavaToolkits</artifactId>
        <version>0.0.2</version>
    </dependency>


    <!--数据结构-->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.3</version>
    </dependency>

    <!--数据存储-->
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.34</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>1.2.3</version>
    </dependency>
    <dependency>
        <groupId>com.github.javaplugs</groupId>
        <artifactId>mybatis-java-time</artifactId>
        <version>0.2</version>
    </dependency>

    <!--系统与进程-->

    <dependency>
        <groupId>io.reactivex</groupId>
        <artifactId>rxjava</artifactId>
        <version>1.0.10</version>
    </dependency>

    <!-- quartz spring 3.1以上才支持quartz 2.2.1 -->
    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz-jobs</artifactId>
        <version>2.2.1</version>
    </dependency>

    <!--测试与发布-->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
    <dependency>
        <groupId>org.skyscreamer</groupId>
        <artifactId>jsonassert</artifactId>
        <version>1.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.7.3</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.4.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.4.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>2.4.1</version>
    </dependency>


    <!--网络请求-->
    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.8.1</version>
    </dependency>


    <!-- 系统缓存 -->

    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache</artifactId>
        <version>2.9.0</version>
    </dependency>

    <!--Memcached-->
    <dependency>
        <groupId>net.spy</groupId>
        <artifactId>spymemcached</artifactId>
        <version>2.11.7</version>
    </dependency>
    <!-- redis -->
    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>2.7.2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-redis</artifactId>
        <version>1.5.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.redisson</groupId>
        <artifactId>redisson</artifactId>
        <version>2.2.4</version>
    </dependency>

    <!--外部接口-->
    <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>jsr305</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.1.0.Final</version>
    </dependency>


</dependencies>

<repositories>
    <repository>
        <id>spring-snapshots</id>
        <url>http://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <url>http://repo.spring.io/milestone</url>
    </repository>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-snapshots</id>
        <url>http://repo.spring.io/snapshot</url>
    </pluginRepository>
    <pluginRepository>
        <id>spring-milestones</id>
        <url>http://repo.spring.io/milestone</url>
    </pluginRepository>
</pluginRepositories>

<!--profile-->
<profiles>

    <profile>
        <!-- 开发环境 -->
        <id>dev</id>
        <properties>
            <!--数据库设计-->
            <db-url>jdbc:mysql://hoteammysql2.mysql.rds.aliyuncs.com:3306/liveforest</db-url>
            <db-username>hoteam_db</db-username>
            <db-password>hoteamConfig1314</db-password>

            <packaging-target>jar</packaging-target>

            <!--依赖作用域设计-->
            <spring-boot-jetty-scope>compiled</spring-boot-jetty-scope>
            <spring-boot-main-class>wx.application.Application</spring-boot-main-class>
        </properties>
        <!-- 默认激活本环境 -->
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>

    <profile>
        <!-- 开发环境 -->
        <id>pro</id>
        <properties>
            <db-url>jdbc:mysql://hoteammysql2.mysql.rds.aliyuncs.com:3306/liveforest</db-url>
            <db-username>hoteam_db</db-username>
            <db-password>hoteamConfig1314</db-password>
            <packaging-target>jar</packaging-target>

            <spring-boot-jetty-scope>compiled</spring-boot-jetty-scope>
            <spring-boot-main-class>wx.application.Application</spring-boot-main-class>


        </properties>
    </profile>

    <profile>
        <!-- 部署环境 -->
        <!--  mvn package -P deploy  -->
        <id>deploy</id>
        <properties>
            <db-url>jdbc:mysql://hoteammysql2.mysql.rds.aliyuncs.com:3306/liveforest</db-url>
            <db-username>hoteam_db</db-username>
            <db-password>hoteamConfig1314</db-password>

            <packaging-target>war</packaging-target>
            <spring-boot-jetty-scope>compiled</spring-boot-jetty-scope>
            <spring-boot-main-class>wx.application.Application4Deploy</spring-boot-main-class>

        </properties>
    </profile>

</profiles>