zoukankan      html  css  js  c++  java
  • springboot pom.xml记

    本文包括:

    1. springboot 基本pom.xml配置

    <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>wqz.zoom</groupId>
      <!--项目名-->
      <artifactId>springbootdemo</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      
      <parent>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-parent</artifactId>
          <version>2.0.4.RELEASE</version>
          <relativePath></relativePath>
      </parent>
      
      <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      </properties>
      
      <dependencies>
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter</artifactId>
          </dependency>
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-test</artifactId>
          </dependency>
      </dependencies>
      <build>
          <plugins>
              <plugin>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-maven-plugin</artifactId>
                  <configuration>
                      <fork>true</fork>
                  </configuration>
              </plugin>
          </plugins>
      </build>
      
    </project>

    需要不同的开发方向,按照下方jar包介绍,添加依赖即可 

    springboot 依赖包详解:

    转自 https://blog.csdn.net/chen15369337607/article/details/78445773

    <?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="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.0http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.zlc</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>demo</name><description>demoprojectforSpringBoot</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.3.RELEASE</version><relativePath/><!--lookupparentfromrepository--></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><!--从父依赖那继承版本号--><!--生产准备的特性,用于帮你监控和管理应用--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!--对高级消息队列协议的支持,通过SpringBoot-rabbit实现--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency><!--对面向切面变成的支持,通过spring-aop和AspectJ--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId></dependency><!--对Springbatch的支持,包括HSQLDB数据库--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-batch</artifactId></dependency><!--对MongoDBNOSQL数据库的支持,包括spring-data-mongodb--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-mongodb</artifactId></dependency><!--通过对REST暴露Springdata仓库的支持,通过Spring-data-rest-webmvc实现--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-rest</artifactId></dependency><!--对java持久化API的支持,包括Spring-data-jpa,spring-orm和Hibernate--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-solr</artifactId></dependency><!--对FreeMarker模板引擎的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId></dependency><!--对基于HATEOAS的RESTful服务的支持,通过Spring-hateoas;--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-hateoas</artifactId></dependency><!--对普通Spring-integration模块的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-integration</artifactId></dependency><!--对JDBC数据库的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><!--对JerseyRESTfulWeb服务框架的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jersey</artifactId></dependency><!--对JTA分布式事务的支持,通过Atomikos--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jta-atomikos</artifactId></dependency><!--对JTA分布式事务的支持,通过Bitronix实现--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jta-bitronix</artifactId></dependency><!--对javax.mail的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId></dependency><!--对spring-mobile的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mobile</artifactId></dependency><!--对spring-security模板引擎的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency><!--对spring-social-facebook的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-social-facebook</artifactId></dependency><!--对spring-social-twitter的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-social-twitter</artifactId></dependency><!--对常用测试依赖的支持,包括JUnit,Hamcrest和Mockito还有Spring-test模块;--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency><!--对Thymeleaf模板引擎的支持,包括和Spring的集成;--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><!--对全栈web开发的支持,包括Tomcat和spring-webmvc;--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--对websocket开发的支持--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId></dependency><!--导入JettyHTTP引擎(作为Tomcat的代替)--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jetty</artifactId></dependency><!--导入SpringBoot的默认日志系统(Logback)--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-logging</artifactId></dependency><!--导入SpringBoot的默认HTTP引擎(Tomcat)--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId></dependency><!--导入UndertowHTTP引擎(作为tomcat的代替)--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-undertow</artifactId></dependency><!--对GemFire分布式数据存储的支持,包括spring-data-gemfire--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-gemfire</artifactId></dependency><!--对java持久化API的支持,包括Spring-data-jpa,spring-orm和Hibernate--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><fork>true</fork><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build></project>原文:https://blog.csdn.net/chen15369337607/article/details/78445773
    springboot pom.xml

    maven配置详解:

    转自 https://www.cnblogs.com/hafiz/p/5360195.html

    配置详解

    2. 配置devtools实现热部署

     spring为开发者提供了一个名为spring-boot-devtools的模块来使Spring Boot应用支持热部署,提高开发者的开发效率,无需手动重启Spring Boot应用。

    devtools的原理

    深层原理是使用了两个ClassLoader,一个Classloader加载那些不会改变的类(第三方Jar包),另一个ClassLoader加载会更改的类,称为restart ClassLoader,这样在有代码更改的时候,原来的restart ClassLoader 被丢弃,重新创建一个restart ClassLoader,由于需要加载的类相比较少,所以实现了较快的重启时间。

    使用需要添加以下的配置:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork> <!-- 此处必须配置,否则 devtools 不会生效-->
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    

    说明:

    (1) devtools可以实现页面热部署(即页面修改后会立即生效,这个可以直接在application.properties文件中配置spring.thymeleaf.cache=false来实现),
    实现类文件热部署(类文件修改后不会立即生效),实现对属性文件的热部署。
    即devtools会监听classpath下的文件变动,并且会立即重启应用(发生在保存时机),注意:因为其采用的虚拟机机制,该项重启是很快的
    (2)配置了true后在修改java文件后也就支持了热启动,不过这种方式是属于项目重启(速度比较快的项目重启),会清空session中的值,也就是如果有用户登陆的话,项目重启后需要重新登陆。

    默认情况下,/META-INF/maven,/META-INF/resources,/resources,/static,/templates,/public这些文件夹下的文件修改不会使应用重启,但是会重新加载(devtools内嵌了一个LiveReload server,当资源发生改变时,浏览器刷新)。

    devtools的配置

    在application.properties中配置spring.devtools.restart.enabled=false,此时restart类加载器还会初始化,但不会监视文件更新。
    在SprintApplication.run之前调用System.setProperty(“spring.devtools.restart.enabled”, “false”);可以完全关闭重启支持,配置内容:

    #热部署生效
    spring.devtools.restart.enabled: true
    #设置重启的目录
    #spring.devtools.restart.additional-paths: src/main/java
    #classpath目录下的WEB-INF文件夹内容修改不重启
    spring.devtools.restart.exclude: WEB-INF/**

    IDEA配置

    当我们修改了Java类后,IDEA默认是不自动编译的,而spring-boot-devtools又是监测classpath下的文件发生变化才会重启应用,所以需要设置IDEA的自动编译:

    (1)File-Settings-Compiler-Build Project automatically

    (2)ctrl + shift + alt + /,选择Registry,勾上 Compiler autoMake allow when app running

    测试

    • 修改类–>保存:应用会重启
    • 修改配置文件–>保存:应用会重启
    • 修改页面–>保存:应用不会重启,但会重新加载,页面会刷新(原理是将spring.thymeleaf.cache设为false,参考:Spring Boot配置模板引擎)
     

     3. 配置打包插件

     springboot 打包插件基本配置

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork> <!-- 此处必须配置,否则 devtools 不会生效-->
                </configuration>
            </plugin>
        </plugins>
    </build>

      

     <build/>标签解析:

     1.分类

           (1)全局配置(project build)

                     针对整个项目的所有情况都有效

           (2)配置(profile build)

                     针对不同的profile配置

    <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"><!– "Project Build" contains more elements than just the BaseBuild set –>  
      <build></build>  
      <profiles>  
        <profile>  
          <!– "Profile Build" contains a subset of "Project Build"s elements –>  
          <build></build>  
        </profile>  
      </profiles>  
    </project>  

     2.配置说明

           (1)基本元素

    <build>  
            <defaultGoal>install</defaultGoal>  
            <directory>${basedir}/target</directory>  
            <finalName>${artifactId}-${version}</finalName>  
            <filters>  
                    <filter>filters/filter1.properties</filter>  
            </filters>  
             ...  
    </build> 

                   1)defaultGoal

                        执行build任务时,如果没有指定目标,将使用的默认值。

                        如上配置:在命令行中执行mvn,则相当于执行mvn install

                  2)directory
                         build目标文件的存放目录,默认在${basedir}/target目录

                  3)finalName

                         build目标文件的名称,默认情况为${artifactId}-${version}

                  4)filter

                         定义*.properties文件,包含一个properties列表,该列表会应用到支持filter的resources中。

                         也就是说,定义在filter的文件中的name=value键值对,会在build时代替${name}值应用到resources中。

                         maven的默认filter文件夹为${basedir}/src/main/filters

             (2)Resources配置

                     用于包含或者排除某些资源文件

     
    <build>  
            ...  
         <resources>  
             <resource>  
                <targetPath>META-INF/plexus</targetPath>  
                <filtering>false</filtering>  
                <directory>${basedir}/src/main/plexus</directory>  
                <includes>  
                    <include>configuration.xml</include>  
                </includes>  
                <excludes>  
                    <exclude>**/*.properties</exclude>  
                </excludes>  
             </resource>  
        </resources>  
        <testResources>  
            ...  
        </testResources>  
        ...  
    </build>  

                   1)resources

                        一个resources元素的列表。每一个都描述与项目关联的文件是什么和在哪里

                  2)targetPath

                        指定build后的resource存放的文件夹,默认是basedir。

                        通常被打包在jar中的resources的目标路径是META-INF

                 3)filtering

                        true/false,表示为这个resource,filter是否激活
                 4)directory

                        定义resource文件所在的文件夹,默认为${basedir}/src/main/resources

                 5)includes

                        指定哪些文件将被匹配,以*作为通配符

                 6)excludes

                       指定哪些文件将被忽略

                 7)testResources

                       定义和resource类似,只不过在test时使用

             (3)plugins配置

                      用于指定使用的插件

     
    <build>  
        ...  
        <plugins>  
            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-jar-plugin</artifactId>  
                <version>2.0</version>  
                <extensions>false</extensions>  
                <inherited>true</inherited>  
                <configuration>  
                    <classifier>test</classifier>  
                </configuration>  
                <dependencies>...</dependencies>  
                <executions>...</executions>  
            </plugin>  
        </plugins>  
    </build> 

                     1)GAV

                          指定插件的标准坐标

                    2)extensions

                          是否加载plugin的extensions,默认为false

                    3)inherited

                          true/false,这个plugin是否应用到该pom的孩子pom,默认为true

                    4)configuration

                          配置该plugin期望得到的properties

                    5)dependencies

                          作为plugin的依赖

                    6)executions

                          plugin可以有多个目标,每一个目标都可以有一个分开的配置,可以将一个plugin绑定到不同的阶段

                          假如绑定antrun:run目标到verify阶段

     
    <build>  
        <plugins>  
            <plugin>  
                <artifactId>maven-antrun-plugin</artifactId>  
                <version>1.1</version>  
                <executions>  
                    <execution>  
                        <id>echodir</id>  
                        <goals>  
                            <goal>run</goal>  
                        </goals>  
                        <phase>verify</phase>  
                        <inherited>false</inherited>  
                        <configuration>  
                            <tasks>  
                                <echo>Build Dir: ${project.build.directory}</echo>  
                            </tasks>  
                        </configuration>  
                    </execution>  
                </executions>  
            </plugin>  
        </plugins>  
    </build>  

                                id:标识,用于和其他execution区分。当这个阶段执行时,它将以这个形式展示[plugin:goal execution: id]。在这里为: [antrun:run execution: echodir]

                               goals:目标列表

                              phase:目标执行的阶段

                              inherit:子类pom是否继承

                              configuration:在指定目标下的配置

            (4)pluginManagement配置

                       pluginManagement的配置和plugins的配置是一样的,只是用于继承,使得可以在孩子pom中使用。

                       父pom:

    <build>  
        ...  
        <pluginManagement>  
            <plugins>  
                <plugin>  
                  <groupId>org.apache.maven.plugins</groupId>  
                  <artifactId>maven-jar-plugin</artifactId>  
                  <version>2.2</version>  
                    <executions>  
                        <execution>  
                            <id>pre-process-classes</id>  
                            <phase>compile</phase>  
                            <goals>  
                                <goal>jar</goal>  
                            </goals>  
                            <configuration>  
                                <classifier>pre-process</classifier>  
                            </configuration>  
                        </execution>  
                    </executions>  
                </plugin>  
            </plugins>  
        </pluginManagement>  
        ...  
    </build>  

                      则在子pom中,我们只需要配置:

     
    <build>  
        ...  
        <plugins>  
            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-jar-plugin</artifactId>  
            </plugin>  
        </plugins>  
        ...  
    </build>  

                    这样就大大简化了孩子pom的配置

  • 相关阅读:
    函数式编程中的基本概念
    【VS】Visual Studio 就可以反编译查看源码了,再见了 Reflector
    【C#】CsvHelper 使用手册
    【C#】使用 System.Globalization.DateTimeFormatInfo 屏蔽系统时间格式对代码的影响
    【swagger】C# 中 swagger 的使用及避坑
    【C#】Newtonsoft.Json 中 JArray 添加数组报错:Could not determine JSON object type for type 'xxx'
    【C#】比较 Random 与 RandomNumberGenerator 生成随机字符串
    【C#】正则进阶
    【C#】写文件时如何去掉编码前缀
    【C#】定时器保活机制引起的内存泄露问题
  • 原文地址:https://www.cnblogs.com/yelao/p/10654719.html
Copyright © 2011-2022 走看看