disconf
disconf copied to clipboard
在使用disconf时 打包成jar后,找不到properties文件的问题怎么解决
使用springboot最后打包为jar,在java -jar 运行时,提示找不到配置文件,配置的文件确定已经自动下载到了根目录下,请问这个问题怎么解决.??
试了一下提供的demo也有同样的问题,
提供具体错误信息
你确定是执行 java -cp . -jar disconf-spring-boot-web-1.0.0.jar 吗
跟 -cp没关系,应该是properties文件打包到Jar包中,代码resource.getFile()是无法访问Jar包内部的文件的,应该用resource.getInputStream(), 有没有哪个选项可以先解压缩再运行的?
你看下 这里 https://github.com/knightliao/disconf-demos-java/tree/master/disconf-standalone-demo 之前有个版本已经fix这个问题了,启动Jar包时,它会将配置文件下载到jar包的外面。 我们公司也是按照这种方式 进行实践的
启用下载的话确实没问题。不过如果不启用下载的话默认是要去classpath里找的,这个时候打包在jar包里的properties文件就无法被读取了。
disconf.enable.remote.conf=false 如果你设置为false的话,disconf 程序还是可以正确读取配置的,前提是你的配置文件要在jar包外面存在。
一般上,是不推荐把配置文件打进包里的。不过你说的确实是个问题,如果打包在jar里我尝试下是否有问题。
好的:D
Same issue.
An alternative temporary solution:
- In
disconf.properties: a). setdisconf.enable.remote.conf=falseto disable remote download b). setdisconf.enable_local_download_dir_in_class_path=falseto disable read properties files in classpath c). notice the defaultdisconf.user_define_download_dir=./disconf/download2 - Put
your-custom.propertiesfiles in directory${project.baseDir}/disconf/download2which is defined in step 1.c - Just restart to get working