我正在使用 Spring springCloudVersion,“2021.0.3”来设置一个配置服务器,该服务器使用我的 gitlab 帐户来存储其文件。我创建了一个具有权限的部署令牌:
读存储库、读注册表、写注册表、读包注册表、写包注册表
然后我在 Spring 服务器 application.properties 中使用它们:
spring.application.name=config-server
spring.application.version=0.1.0
server.port=8012
spring.cloud.config.server.git.uri=https://gitlab.com/[account]/[repo]
spring.cloud.config.server.git.skip-ssl-validation=true
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.default-label=main
spring.cloud.config.server.git.basedir=https://gitlab.com/[account]/[repo]
spring.cloud.config.server.git.username=[my-token-username]
spring.cloud.config.server.git.password=[my-token-password]
我在启动时收到关于不绑定基本目录的错误,直到我将与 spring.cloud.config.server.git.uri 中相同的 uri 放在那里(它们现在相同,但感觉不对)
当我尝试启动 ConfigServerApplication 时,我得到以下信息:
ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'defaultEnvironmentRepository' defined in class path resource [org/springframework/cloud/config/server/config/DefaultRepositoryConfiguration.class]: Unsatisfied dependency expressed through method 'defaultEnvironmentRepository' parameter 1; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'multipleJGitEnvironmentProperties': Could not bind properties to 'MultipleJGitEnvironmentProperties' : prefix=spring.cloud.config.server.git, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.cloud.config.server.git.basedir' to java.io.File
2022-06-30 12:04:53.020 INFO 1594 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-06-30 12:04:53.026 INFO 1594 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-06-30 12:04:53.033 ERROR 1594 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'spring.cloud.config.server.git.basedir' to java.io.File:
Property: spring.cloud.config.server.git.basedir
Value: https://gitlab.com/[account]/[repo]
Origin: class path resource [application.properties] - 9:40
Reason: failed to convert java.lang.String to java.io.File (caused by java.lang.IllegalStateException: Could not retrieve file for URL [https://gitlab.com/[account]/[repo]]: URL [https://gitlab.com/[account]/[repo]] cannot be resolved to absolute file path because it does not reside in the file system: https://gitlab.com/[account]/[repo]
我不知道它正在尝试访问什么文件 - 在该存储库中我有
我认为属性文件就是它试图访问的内容?
我尝试使用我的帐户凭据和部署令牌,得到相同的结果。我没有尝试部署密钥,因为这不会在本地访问,而是通过云访问。
终于找到了 - 我必须补充:
spring.profiles.active=本机
并删除
spring.cloud.config.server.git.basedir
如果删除 spring.cloud.config.server.git.basedir 在属性文件中哪里配置 git repo 下载文件夹?