欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用springBoot項(xiàng)目配置文件位置調(diào)整到打包外

 更新時(shí)間:2021年08月10日 17:27:47   作者:langzilige  
這篇文章主要介紹了使用springBoot項(xiàng)目配置文件位置調(diào)整到打包外,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

項(xiàng)目目錄

問題痛點(diǎn):

當(dāng)我們打包一個(gè)項(xiàng)目的時(shí)候,springboot打包的jar都是把resouce下的配置文件打進(jìn)去了,這樣就沒發(fā)修改配置文件

解決方案

  • 1.打包的時(shí)候指定打包路徑
  • 2.將配置文件從resouce下面移出來

這兩種方案其實(shí)都涉及到一個(gè)maven打包配置問題

首先來談?wù)剬⑴渲梦募膔esouce下面移出來怎么解決

1在項(xiàng)目src同級別目錄建

config目錄

2.將resouce下的

application.yaml 文件移到config目錄下方便打包后可以配置application文件中相關(guān)配置

pom.xml中的打包配置

 <build>
        <resources>
            <resource>
                <directory>config</directory>
                <includes>
                    <include>*.yaml</include>
                    <include>*.xml</include>
                    <include>*.conf</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
<!--過濾掉的 -->
                <!--                <excludes>-->
                <!--                    <exclude>**/*.properties</exclude>-->
                <!--                    <exclude>**/*.xml</exclude>-->
                <!--                    <exclude>**/*.yml</exclude>-->
                <!--                </excludes>-->
                <filtering>false</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions></executions>
                <configuration>
                    <!-- 生成可執(zhí)行的jar的名字:xxx-exec.jar -->
                    <!-- 不固定,寫成abcd都可以 -->
                    <classifier>exec</classifier>
                    <mainClass>com.cloudwise.douc.zabbix.api.DoucZabbixApplication</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/assembly/assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

assembly.xml配置

<assembly
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    <id>bin</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <includeBaseDirectory>true</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>${project.basedir}</directory>
            <outputDirectory>./</outputDirectory>
            <includes>
                <include>README*</include>
                <include>LICENSE*</include>
                <include>NOTICE*</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>config</directory>
            <outputDirectory>config</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>bin</directory>
            <outputDirectory>bin</outputDirectory>
            <fileMode>777</fileMode>
        </fileSet>
        <fileSet>
            <directory>target</directory>
            <outputDirectory>lib</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
    </fileSets>
    <dependencySets>
        <dependencySet>
            <!--是否把本項(xiàng)目添加到依賴文件夾下-->
            <useProjectArtifact>true</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
            <!--將scope為runtime的依賴包打包-->
            <!--<scope>runtime</scope>-->
        </dependencySet>
    </dependencySets>
</assembly>

sh啟動(dòng)類shell腳本

#!/bin/bash
PWDPATH=`dirname $0`
COMM_HOME=`cd $PWDPATH && cd .. && pwd`
cd $COMM_HOME
start () {
    JVM_OPTS="
     -server
     -Xms1g
     -Xmx1g
     -XX:+AlwaysPreTouch
     -XX:+UseG1GC
     -XX:MaxGCPauseMillis=2000
     -XX:GCTimeRatio=4
     -XX:InitiatingHeapOccupancyPercent=30
     -XX:G1HeapRegionSize=8M
     -XX:ConcGCThreads=2
     -XX:G1HeapWastePercent=10
     -XX:+UseTLAB
     -XX:+ScavengeBeforeFullGC
     -XX:+DisableExplicitGC
     -XX:+PrintGCDetails
     -XX:-UseGCOverheadLimit
     -XX:+PrintGCDateStamps
     -Xloggc:logs/gc.log
     -Dlog4j2.configurationFile=config/log4j2.xml
    "
    export CLASSPATH=$JAVA_HOME/jre/lib/*:$JAVA_HOME/lib/*:$COMM_HOME/lib/*
#    啟動(dòng)類路徑
    export MAINCLASS="com.gug.api.AdimApplication"
    case $1 in
    -b )
        nohup java $JVM_OPTS -cp $CLASSPATH $MAINCLASS 1>/dev/null 2>&1 &
    ;;
    -d )
        java $JVM_OPTS -classpath $CLASSPATH $MAINCLASS
    ;;
    esac
    echo -e '\r'
}
case $1 in
restart )
    echo stop
    PID=`ps avx|grep $COMM_HOME|grep -v 'grep'|awk '{print $1}'`
    if  [ ! -n "$PID" ] ;then
       echo "The current process does not exist."
    else
       kill $PID
       echo "The process has been successfully stopped."
    fi
    echo start
    if [ ! -n "$2" ] ;then
	echo "After start, you must add parameters -d or -b. See help for details."
    else
        start $2 -b
    fi
;;
start )
    echo start
    if [ ! -n "$2" ] ;then
	echo "After start, you must add parameters -d or -b. See help for details."
    else
        start $2
    fi
;;
stop )
    echo stop
    PID=`ps avx|grep $COMM_HOME|grep -v 'grep'|awk '{print $1}'`
    if  [ ! -n "$PID" ] ;then
       echo "The current process does not exist."
    else
       kill $PID
       echo "The process has been successfully stopped."
    fi
;;
pid )
    PID=`ps avx|grep $COMM_HOME|grep -v 'grep'|awk '{print $1}'`
    if  [ ! -n "$PID" ] ;then
       echo "The current process does not exist."
    else
       echo "pid : "${PID}
    fi
;;
status )
    PID=`ps avx|grep $COMM_HOME|grep -v 'grep'|awk '{print $1}'`
    if  [ ! -n "$PID" ] ;then
       echo "dead"
    else
       echo "running"
    fi
;;
help )
    echo 'start    -d or -b     Start the service DEBUG mode or background mode.'
    echo 'stop                  Stop the service running in the background.'
    echo 'pid                   Gets the current process id information.'
    echo 'status                Gets the current service status information.'
;;
* )
    echo Command error, please enter help
;;
esac

總結(jié):

當(dāng)打包過程中出現(xiàn)各種問題后,及時(shí)的去查找問題,一般注意pom中的配置打包是否沒有把某些包打進(jìn)去還有就是啟動(dòng)sell腳本通過 ./Aplication.sh start -d 顯示啟動(dòng)日志

到此這篇使用springBoot項(xiàng)目配置文件位置調(diào)整到打包外文章就介紹到這了,更多相關(guān)springBoot項(xiàng)目配置文件位置調(diào)整到打包外的內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java工具類實(shí)現(xiàn)文件壓縮zip以及解壓縮功能

    java工具類實(shí)現(xiàn)文件壓縮zip以及解壓縮功能

    這篇文章主要給大家介紹了關(guān)于java工具類實(shí)現(xiàn)文件壓縮zip以及解壓縮功能的相關(guān)資料,文中主要使用使用的是hutool工具類,Hutool是一個(gè)Java工具類庫,由國內(nèi)的程序員loolly開發(fā),目的是提供一些方便、快捷、實(shí)用的工具類和工具方法,需要的朋友可以參考下
    2024-02-02
  • springboot接收excel數(shù)據(jù)文件去重方式

    springboot接收excel數(shù)據(jù)文件去重方式

    文章主要介紹了如何在Spring?Boot中實(shí)現(xiàn)文件上傳并入庫的功能,包括讀取Excel文件、生成Entity對象、使用MergeInto語句進(jìn)行數(shù)據(jù)庫操作以及注意事項(xiàng)
    2024-12-12
  • Spring中@PropertySource的使用方法和運(yùn)行原理詳解

    Spring中@PropertySource的使用方法和運(yùn)行原理詳解

    這篇文章主要介紹了Spring中@PropertySource的使用方法和運(yùn)行原理詳解,PropertySource注解可以方便和靈活的向Spring的環(huán)境容器(org.springframework.core.env.Environment?Environment)中注入一些屬性,這些屬性可以在Bean中使用,需要的朋友可以參考下
    2023-11-11
  • java 自定義類比較器代碼

    java 自定義類比較器代碼

    這篇文章主要介紹了java 自定義類比較器代碼,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • SpringBoot中配置多數(shù)據(jù)源的方法詳解

    SpringBoot中配置多數(shù)據(jù)源的方法詳解

    這篇文章主要為大家詳細(xì)介紹了SpringBoot中配置多數(shù)據(jù)源的方法的相關(guān)知識,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-02-02
  • 將InputStream轉(zhuǎn)化為base64的實(shí)例

    將InputStream轉(zhuǎn)化為base64的實(shí)例

    這篇文章主要介紹了將InputStream轉(zhuǎn)化為base64的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • java常見面試題及答案匯總

    java常見面試題及答案匯總

    本文提供Java面試題集錦,涵蓋封裝、繼承、多態(tài)等核心概念,旨在幫助求職者全面復(fù)習(xí),提升面試表現(xiàn),從基礎(chǔ)知識到實(shí)際應(yīng)用,內(nèi)容豐富,適合各類求職者,需要的朋友可以參考下
    2024-09-09
  • PowerJob的AliOssService工作流程源碼解讀

    PowerJob的AliOssService工作流程源碼解讀

    這篇文章主要介紹了PowerJob的AliOssServiceg工作流程源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2024-01-01
  • spring cloud gateway網(wǎng)關(guān)路由分配代碼實(shí)例解析

    spring cloud gateway網(wǎng)關(guān)路由分配代碼實(shí)例解析

    這篇文章主要介紹了spring cloud gateway網(wǎng)關(guān)路由分配代碼實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-01-01
  • Java?不同版本的?Switch語句

    Java?不同版本的?Switch語句

    本文主要介紹了Java不同版本的Switch語句,自Java13以來,Switch表達(dá)式就被添加到Java核心庫中,下面我們將介紹舊的Java?Switch語句和新的Switch語句的區(qū)別,需要的朋友可以參考一下
    2022-06-06

最新評論