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的配置


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM