我想在应用程序的开发阶段将git存储库放置在类路径正上方的文件夹中。
当前,我将其作为Spring Cloud git URI:
spring.cloud.config.server.git.uri=file://${user.dir}/cloud-configuration-repository
此URI指向类路径正上方的文件夹。
但是,在运行时出现此错误。
***************************
APPLICATION FAILED TO START
***************************
Description:
Invalid config server configuration.
Action:
If you are using the git profile, you need to set a Git URI in your configuration. If you are using a native profile and have spring.cloud.config.server.bootstrap=true, you need to use a composite configuration.
编辑:这是我希望拥有的项目结构:
Project
├── _.idea
├── src
| ├── main
| └── test
├── target
└── cloud-configuration-repository
答案 0 :(得分:1)
从文档中:
https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html
2.1.3文件系统后端: Config Server中还有一个“本机”配置文件,该配置文件不使用Git,而是从本地类路径或文件系统加载配置文件 (您要使用spring.cloud.config.server.native.searchLocations指向的任何静态URL)。要使用本机配置文件,请使用spring.profiles.active = native启动Config Server。
因此,在您的情况下,它将是:
spring.profiles.active=native
spring.cloud.config.server.native:searchLocations=file://${user.dir}/cloud-configuration-repository
答案 1 :(得分:0)
我遇到了与@Nuradin完全相同的问题,问题是我在错误的文件中添加了spring.cloud.config.server.git.uri属性。我需要将该行添加到application.properties文件中,而不是我的service.properties文件中。这是我的application.properties文件现在的样子:
getService(endpoint) {
// Assume it will set some values in header & cookie from beforeGetService()
let url = 'https://jsonplaceholder.typicode.com'+endpoint;
return this.beforeGetService().pipe(
concatMap(res => this.http.get(url)
)
}
public beforeGetService() {
// Assume this service will do some updates on headers & cookie
return this.http.get('https://jsonplaceholder.typicode.com/todos/1');
}
我正在Windows 10上使用Spring Tool Suite。
答案 2 :(得分:0)
我在应用程序中遇到类似的错误,这是针对相同问题的解决方法:
a)请在您的SpringBootApplication类中添加@EnableConfigServer批注
@EnableConfigServer
@SpringBootApplication
public class SpringsCloudConfigServerApplication {
--
--
}
b)在您的application.properties文件中添加以下条目
spring.profiles.active=native
spring.cloud.config.server.native:searchLocations=file://ClasspathOfYourFile
或
spring.profiles.active=native
server.cloud.config.server.git.uri=file://ClasspathOfYourFile