這是我最初的配置:
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: file:///home/codependent/git/scc-dev
repos:
dev:
pattern: '*/dev'
uri: file:///home/codependent/git/scc-dev
pre:
pattern: '*/pre'
uri: file:///home/codependent/git/scc-pre
pro:
pattern: '*/pro'
uri: file:///home/codependent/git/scc-pro
有一個默認回購的情況下,沒有環境的匹配,並根據一圖中的三個回購。
這個想法是有另一個基地回購(最低優先級),總是會被加載,也取決於環境。這個基本倉庫包含一個application.yml,其中共享屬性由不同的團隊管理。
顯然沒有通過陽明性能做,所以我不得不手動定義豆的方式,這是代碼要做到這一點:
@Bean
public EnvironmentRepository baseEnvironmentRepository(){
ConfigurableEnvironment ce = new StandardServletEnvironment();
PatternMatchingJGitEnvironmentRepository devRepo = new PatternMatchingJGitEnvironmentRepository("file:///home/codependent/git/scc-ops-dev");
devRepo.setEnvironment(ce);
devRepo.setForcePull(false);
devRepo.setPattern(new String[]{ "*/dev" });
PatternMatchingJGitEnvironmentRepository preRepo = new PatternMatchingJGitEnvironmentRepository("file:///home/codependent/git/scc-ops-pre");
preRepo.setEnvironment(ce);
preRepo.setForcePull(false);
preRepo.setPattern(new String[]{ "*/pre" });
PatternMatchingJGitEnvironmentRepository proRepo = new PatternMatchingJGitEnvironmentRepository("file:///home/codependent/git/scc-ops-pro");
proRepo.setEnvironment(ce);
proRepo.setForcePull(false);
proRepo.setPattern(new String[]{ "*/pro" });
Map<String, PatternMatchingJGitEnvironmentRepository> map = new HashMap<>();
map.put("dev", devRepo);
map.put("pre", preRepo);
map.put("pro", proRepo);
MultipleJGitEnvironmentRepository multiple = new MultipleJGitEnvironmentRepository(new StandardServletEnvironment());
multiple.setUri("file:///home/codependent/git/scc-ops-dev");
multiple.setRepos(map);
multiple.setOrder(Ordered.LOWEST_PRECEDENCE);
return multiple;
}
@Bean
public EnvironmentRepository environmentRepository(){
ConfigurableEnvironment ce = new StandardServletEnvironment();
PatternMatchingJGitEnvironmentRepository devRepo = new PatternMatchingJGitEnvironmentRepository("file:///home/codependent/git/scc-dev");
devRepo.setEnvironment(ce);
devRepo.setForcePull(false);
devRepo.setPattern(new String[]{ "*/dev" });
PatternMatchingJGitEnvironmentRepository preRepo = new PatternMatchingJGitEnvironmentRepository("file:///home/codependent/git/scc-pre");
preRepo.setEnvironment(ce);
preRepo.setForcePull(false);
preRepo.setPattern(new String[]{ "*/pre" });
PatternMatchingJGitEnvironmentRepository proRepo = new PatternMatchingJGitEnvironmentRepository("file:///home/codependent/git/scc-pro");
proRepo.setEnvironment(ce);
proRepo.setForcePull(false);
proRepo.setPattern(new String[]{ "*/pro" });
Map<String, PatternMatchingJGitEnvironmentRepository> map = new HashMap<>();
map.put("dev", devRepo);
map.put("pre", preRepo);
map.put("pro", proRepo);
MultipleJGitEnvironmentRepository multiple = new MultipleJGitEnvironmentRepository(new StandardServletEnvironment());
multiple.setUri("file:///home/codependent/git/scc-dev");
multiple.setRepos(map);
multiple.setOrder(Ordered.HIGHEST_PRECEDENCE);
return multiple;
}
可悲的是,我還沒有嘗試過自己,但在如果您沒有在網上找到任何有用的信息,請嘗試官方文檔http://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.3.1.RELEASE/ - 他們有一個模式匹配部分和多個存儲庫,這可能會幫助你 – maydawn
它不。多個存儲庫功能旨在按團隊分離配置。一旦找到匹配就停止。 – spencergibb
@spencergibb你認爲它可以被認爲是未來的功能?我認爲這是必要的,在我們公司的某些屬性,例如數據庫配置(url,db用戶,db密碼)只能由基礎設施團隊設置,這就是爲什麼我們需要他們在不同的回購中,只允許團隊更新道具 – codependent