使用springBoot项目配置文件位置调整到打包外
项目目录
文章图片
问题痛点:
当我们打包一个项目的时候,springboot打包的jar都是把resouce下的配置文件打进去了,这样就没发修改配置文件
解决方案
- 1.打包的时候指定打包路径
- 2.将配置文件从resouce下面移出来
首先来谈谈将配置文件从resouce下面移出来怎么解决
1在项目src同级别目录建
config目录
2.将resouce下的
application.yaml 文件移到config目录下方便打包后可以配置application文件中相关配置
pom.xml中的打包配置
config *.yaml *.xml *.conf true src/main/resources false org.apache.maven.plugins maven-compiler-plugin3.5.1 1.8 1.8 org.springframework.boot spring-boot-maven-pluginexec com.cloudwise.douc.zabbix.api.DoucZabbixApplication org.apache.maven.plugins maven-assembly-pluginsrc/main/assembly/assembly.xml make-assembly packagesingle
assembly.xml配置
bin tar.gz true ${project.basedir} ./ README* LICENSE* NOTICE* config config bin bin 777 target lib *.jar true lib
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项目配置文件位置调整到打包外的内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- 由浅入深理解AOP
- 【译】20个更有效地使用谷歌搜索的技巧
- Activiti(一)SpringBoot2集成Activiti6
- mybatisplus如何在xml的连表查询中使用queryWrapper
- MybatisPlus|MybatisPlus LambdaQueryWrapper使用int默认值的坑及解决
- MybatisPlus使用queryWrapper如何实现复杂查询
- SpringBoot调用公共模块的自定义注解失效的解决
- 解决SpringBoot引用别的模块无法注入的问题
- iOS中的Block
- Linux下面如何查看tomcat已经使用多少线程