File System Backend

Config Server 中还有一个 “native” 个人资料,它不使用 Git,而是从本地类路径或文件系统(您可以使用 spring.cloud.config.server.native.searchLocations 指向的任何静态 URL)加载配置文件。要使用本机个人资料,请使用 spring.profiles.active=native 启动配置服务器。

There is also a “native” profile in the Config Server that does not use Git but loads the config files from the local classpath or file system (any static URL you want to point to with spring.cloud.config.server.native.searchLocations). To use the native profile, launch the Config Server with spring.profiles.active=native.

请记住,对文件资源使用 file: 前缀(通常没有前缀的默认值是类路径)。与任何 Spring Boot 配置一样,您可以嵌入 ${} 样式的环境占位符,但请记住,Windows 中的绝对路径需要一个额外的 /(例如,file:///${user.home}/config-repo)。

Remember to use the file: prefix for file resources (the default without a prefix is usually the classpath). As with any Spring Boot configuration, you can embed ${}-style environment placeholders, but remember that absolute paths in Windows require an extra / (for example, file:///${user.home}/config-repo).

searchLocations 的默认值与一个本地 Spring Boot 应用程序相同(也就是 [classpath:/, classpath:/config, file:./, file:./config])。这不会将服务器的 application.properties 暴露给所有客户端,因为在将任何属性源发送给客户端之前会将其从服务器中删除。

The default value of the searchLocations is identical to a local Spring Boot application (that is, [classpath:/, classpath:/config, file:./, file:./config]). This does not expose the application.properties from the server to all clients, because any property sources present in the server are removed before being sent to the client.

文件系统后端非常适合快速入门和测试。要在生产中使用它,您需要确保文件系统是可靠的,并且在配置服务器的所有实例中共享。

A filesystem backend is great for getting started quickly and for testing. To use it in production, you need to be sure that the file system is reliable and shared across all instances of the Config Server.

搜索位置可以包含 {application}{profile}{label} 的占位符。通过这种方式,您可以隔离路径中的目录,并选择对您有意义的策略(例如每个应用程序的一个子目录或每个个人资料的一个子目录)。

The search locations can contain placeholders for {application}, {profile}, and {label}. In this way, you can segregate the directories in the path and choose a strategy that makes sense for you (such as subdirectory per application or subdirectory per profile).

如果您在搜索位置中不使用占位符,该仓库还会将 HTTP 资源的 {label} 参数追加到搜索路径上的一个后缀,以便从每个搜索位置*和*一个与标签同名的子目录加载属性文件(标记属性在 Spring Environment 中优先)。因此,不使用占位符的默认行为与添加以 /{label}/ 结尾的搜索位置相同。例如,file:/tmp/configfile:/tmp/config,file:/tmp/config/{label} 相同。可以通过设置 spring.cloud.config.server.native.addLabelLocations=false 来禁用此行为。

If you do not use placeholders in the search locations, this repository also appends the {label} parameter of the HTTP resource to a suffix on the search path, so properties files are loaded from each search location and a subdirectory with the same name as the label (the labelled properties take precedence in the Spring Environment). Thus, the default behaviour with no placeholders is the same as adding a search location ending with /{label}/. For example, file:/tmp/config is the same as file:/tmp/config,file:/tmp/config/{label}. This behavior can be disabled by setting spring.cloud.config.server.native.addLabelLocations=false.