使用springBoot项目配置文件位置调整到打包外

项目目录 使用springBoot项目配置文件位置调整到打包外
文章图片

问题痛点: 当我们打包一个项目的时候,springboot打包的jar都是把resouce下的配置文件打进去了,这样就没发修改配置文件
解决方案

  • 1.打包的时候指定打包路径
  • 2.将配置文件从resouce下面移出来
这两种方案其实都涉及到一个maven打包配置问题
首先来谈谈将配置文件从resouce下面移出来怎么解决
1在项目src同级别目录建
config目录
2.将resouce下的
application.yaml 文件移到config目录下方便打包后可以配置application文件中相关配置
pom.xml中的打包配置
config*.yaml*.xml*.conftruesrc/main/resourcesfalseorg.apache.maven.pluginsmaven-compiler-plugin3.5.11.81.8org.springframework.bootspring-boot-maven-pluginexeccom.cloudwise.douc.zabbix.api.DoucZabbixApplicationorg.apache.maven.pluginsmaven-assembly-pluginsrc/main/assembly/assembly.xmlmake-assemblypackagesingle

assembly.xml配置
bintar.gztrue${project.basedir}./README*LICENSE*NOTICE*configconfigbinbin777targetlib*.jartruelib

sh启动类shell脚本
#!/bin/bashPWDPATH=`dirname $0`COMM_HOME=`cd $PWDPATH && cd .. && pwd`cd $COMM_HOMEstart () {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/*#启动类路径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; ; esacecho -e '\r'}case $1 inrestart )echo stopPID=`ps avx|grep $COMM_HOME|grep -v 'grep'|awk '{print $1}'`if[ ! -n "$PID" ] ; thenecho "The current process does not exist."elsekill $PIDecho "The process has been successfully stopped."fiecho startif [ ! -n "$2" ] ; then echo "After start, you must add parameters -d or -b. See help for details."elsestart $2 -bfi; ; start )echo startif [ ! -n "$2" ] ; then echo "After start, you must add parameters -d or -b. See help for details."elsestart $2fi; ; stop )echo stopPID=`ps avx|grep $COMM_HOME|grep -v 'grep'|awk '{print $1}'`if[ ! -n "$PID" ] ; thenecho "The current process does not exist."elsekill $PIDecho "The process has been successfully stopped."fi; ; pid )PID=`ps avx|grep $COMM_HOME|grep -v 'grep'|awk '{print $1}'`if[ ! -n "$PID" ] ; thenecho "The current process does not exist."elseecho "pid : "${PID}fi; ; status )PID=`ps avx|grep $COMM_HOME|grep -v 'grep'|awk '{print $1}'`if[ ! -n "$PID" ] ; thenecho "dead"elseecho "running"fi; ; help )echo 'start-d or -bStart the service DEBUG mode or background mode.'echo 'stopStop the service running in the background.'echo 'pidGets the current process id information.'echo 'statusGets the current service status information.'; ; * )echo Command error, please enter help; ; esac

总结: 当打包过程中出现各种问题后,及时的去查找问题,一般注意pom中的配置打包是否没有把某些包打进去还有就是启动sell脚本通过 ./Aplication.sh start -d 显示启动日志
【使用springBoot项目配置文件位置调整到打包外】到此这篇使用springBoot项目配置文件位置调整到打包外文章就介绍到这了,更多相关springBoot项目配置文件位置调整到打包外的内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

    推荐阅读