我正在尝试在docker容器中运行一个java maven (spring boot)项目来访问zoho api。
对于身份验证,我需要一个文件zoho-oauthtokens.properties,它位于src/main/resources中,我从另一个名为oauth_configuration.properties的属性文件中引用它,如下所示:oauth_tokens_file_path=src/main/resources/zoho-oauthtokens.properties
只要我在eclipse中将应用程序作为spring应用程序运行,一切都会正常工作,但一旦我在docker容器中运行它,我就会得到:com.zoho.crm.library.exception.ZCRMException com.zoho.oauth.common.ZohoOAuthException. Caused by : com.zoho.oauth.common.ZohoOAuthException. Caused by : java.io.FileNotFoundException: src/main/resources/zoho-oauthtokens.properties (No such file or directory)
那么,我如何正确地引用资源文件,以便在docker容器中运行它时也能找到它?有什么想法吗?
我试过了:
oauth_tokens_file_path=src/main/resources/zoho-oauthtokens.properties
oauth_tokens_file_path=classpath:/zoho-oauthtokens.properties
oauth_tokens_file_path=/zoho-oauthtokens.properties
oauth_tokens_file_path=zoho-oauthtokens.properties
在将其放入我的项目的根文件夹之后:oauth_tokens_file_path=/zoho-oauthtokens.properties
oauth_tokens_file_path=zoho-oauthtokens.properties
最好的,尼尔斯
编辑:它尝试了更多选项:
../../../zoho-oauthtokens.properties
./zoho-oauthtokens.properties
/BOOT-INF/classes/zoho-oauthtokens.properties
BOOT-INF/classes/zoho-oauthtokens.properties
此外,我还检查了maven构建之后的jar文件。这是相关文件所在的位置:
BOOT-INF/classes/de/xxx/xxx/Application.class
BOOT-INF/classes/zoho-oauthtokens.properties
BOOT-INF/classes/oauth_configuration.properties
发布于 2020-03-18 09:47:18
你试过了吗?
oauth_tokens_file_path=classpath*:zoho-oauthtokens.properties因为它在不同的罐子里。同样,我不确定zoho-oauthtokens.properties是如何加载到代码中的。值得一试。
https://stackoverflow.com/questions/54113212
复制相似问题