- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试将代码构建到我们的基础 pom 中,它通过 Eureka 自动配置 Spring Cloud Config 服务器查找。我们这样做是为了避免为构建微服务的开发人员模板化 .yml 属性。例如,我们想要 java 配置从这些属性触发的所有行为:
spring:
application:
name: MyMicroservice
cloud:
config:
enabled: true
server:
prefix: /diagnostics/admin/config
failFast: true
discovery:
enabled: true
serviceId: echo
management:
context-path: /diagnostics/admin
eureka:
password: password
client:
serviceUrl:
defaultZone: http://user:${eureka.password}@localhost:8761/eureka/
instance:
leaseRenewalIntervalInSeconds: 10
statusPageUrlPath: /diagnostics/admin/info
healthCheckUrlPath: /diagnostics/admin/health
经过多次试验,除了 Eureka 发现的配置服务器(导致没有覆盖配置属性)之外,以下方法大部分都有效:
@Order(-1)
public class AdditionalBootstrapPropertySourceLocator implements PropertySourceLocator {
@Override
public PropertySource<?> locate(Environment environment) {
Map<String, Object> theBootstrapYmlConfig = new HashMap<>();
theBootstrapYmlConfig.put("spring.cloud.config.enabled", new Boolean(true));
theBootstrapYmlConfig.put("spring.cloud.config.server.prefix", "/diagnostics/admin/config");
theBootstrapYmlConfig.put("spring.cloud.config.failFast", new Boolean(true));
theBootstrapYmlConfig.put("spring.cloud.config.discovery.enabled", new Boolean(true));
theBootstrapYmlConfig.put("spring.cloud.config.discovery.serviceId", "echo");
theBootstrapYmlConfig.put("management.context-path", "/diagnostics/admin");
theBootstrapYmlConfig.put("eureka.client.serviceUrl.defaultZone", "http://user:password@localhost:8761/eureka/");
theBootstrapYmlConfig.put("eureka.instance.leaseRenewalIntervalInSeconds", new Integer(10));
theBootstrapYmlConfig.put("eureka.instance.statusPageUrlPath", "/diagnostics/admin/info");
theBootstrapYmlConfig.put("eureka.instance.healthCheckUrlPath", "/diagnostics/admin/health");
return new MapPropertySource("myExtraBootstrap", theBootstrapYmlConfig);
}
}
而且我似乎也需要这个 Bean:
@ConditionalOnWebApplication
@Configuration
@Import(EurekaClientAutoConfiguration.class)
public class WorkfrontDiscoveryClientConfigServiceBootstrapConfiguration {
@Bean
@ConditionalOnClass({ DiscoveryClient.class, ConfigServicePropertySourceLocator.class })
@ConditionalOnMissingBean
DiscoveryClientConfigServiceBootstrapConfiguration discoveryClientConfigServiceBootstrapConfiguration() {
DiscoveryClientConfigServiceBootstrapConfiguration discoveryClientConfigServiceBootstrapConfiguration =
new DiscoveryClientConfigServiceBootstrapConfiguration();
return discoveryClientConfigServiceBootstrapConfiguration;
}
}
最后,我将两者都放入 spring.factories 以确保它们被构建。问题是 PropertySourceLocator 从未用于在 ConfigServicePropertySourceLocator 中构造调用以检索属性。无论我做什么,我似乎都无法匹配在 bootstrap.yml 中指定属性会产生的行为。
4天后编辑
这里的关键因素(和限制)是能够通过 Eureka 查找配置服务器。在当前的 spring cloud 版本 (1.0.2) 中,对于我上面的 config-lookup-through-eureka java property source 配置,在 spring 初始化周期中过早地检索和构造属性源。另外,如果 Eureka 服务器在 Bootstrap 启动时速度很慢或不可用,则当 Eureka 最终出现时,Config 服务器属性源永远不会被重建。这在我看来是一个错误。
我通过消除通过 Eureka 查找配置服务器的概念解决了这一切,并在 bootstrap.yml 中要求这个最小配置:
spring:
application:
name: MyMicroservice
cloud:
config:
uri: http://localhost:8888/diagnostics/admin/config
eureka:
client:
serviceUrl:
defaultZone: http://user:password@localhost:8761/eureka/
然后在 java AdditionalBootstrapPropertySourceLocator 中设置其余部分
30 天后编辑
Java 配置 Bootstrap 属性仍然是一个挑战。我这样做是因为我正在开发一个没有模板或代码生成的框架(spring boot 的前提)。我已经在混合中添加了 spring-retry 并且 client-to-config 被重试但是重新注册到 Eureka 没有。这就是为什么必须为我放弃 Eureka-first 的原因。我投票赞成将 spring-retry 集成到 Eureka 注册过程中,这样我就可以回到 Eureka-first 来获取我的框架。仍在 Spring Cloud 1.0.2 上。
100 天后编辑
更新我们结束的地方。继续我们避免属性模板化、在代码中强制执行策略和实践的口头禅......并且继续没有 Eureka 优先概念,我们放弃了 PropertySourceLocator 并简单地使用了一个 SpringApplicationRunListener,如下所示:
public class OurFrameworkProperties implements SpringApplicationRunListener {
:
public void started() {
if (TestCaseUtils.isRunningFromTestCase()) {
System.setProperty("spring.cloud.config.failFast", "false");
System.setProperty("spring.cloud.config.enabled", "false");
System.setProperty("eureka.client.enabled", "false");
} else {
// set production values same way
}
}
}
请注意,每次您的 Spring 应用程序运行或获取 Actuator refresh() 时,这个 started() 实际上在 spring 代码中被调用两次(顺便说一句,一次没有传递任何程序参数)。
最佳答案
如果您的 PropertySourceLocator
列在 spring.factories
中(我假设是 BootstrapConfiguration
),那么它需要是一个 @组件
(或者甚至是 @Configuration
)。
关于java - 使用 Java 而不是 bootstrap.yml 通过 Eureka 进行 Spring Cloud Config Server 查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30988822/
任何人都可以详细说明用途是什么(何时使用)asp.net web应用中的web.config,web.config.debug,web.config.release文件?? 最佳答案 它是用于更改调试
我正在尝试创建一个 nuget 包,它将添加一个 DLL 并在正确的配置文件中配置它。该包可用于控制台/表单应用程序或 Web 应用程序,因此我想更新相应的配置文件,app.config 或 web.
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 有关您编写的代码问题的问题必须在问题本身中描述具体问题 - 并包含有效代码 以重现它。
我正在开发一个 MVCPortlet。我的 view.jsp 中有一个链接,它调用 liferay 中 portlet 类中的一个方法。 ">Comlex This is the Refahi
我一直在尝试了解如何使用不同的配置文件,我刚刚发现 this link这非常有帮助。唯一的问题是,似乎只有在“发布”解决方案时才会考虑转换,而如果您现在只是进行通用调试或运行,则不会考虑转换。 通常这
我想处理我的 jsx 代码,所以我像这样编写 webpakc.config.js: { test: /\.js$/, loaders: ['react-hot', 'babel-loa
我正在使用 Web.Config 转换将我的应用程序部署到 Azure。我的服务中还有 2 个站点,一个公共(public)网站和一个私有(private) WCF 站点端点。我正在部署multipl
我正在使用 spring security 4.2.5.RELEASE 和 spring 4.3.16.RELEASE我的 XML 配置工作正常,如下所示
config.json 和 config.js 之间有什么区别?我必须同时使用两者吗?我什么时候需要使用其中之一? (https://docs.strongloop.com/display/publi
我运行了 Doctrine 控制台工具: $ php vendor/doctrine/orm/bin/doctrine orm:schema-tool:create --dump-sql 我得到了这个
我正在尝试将 Doctrine ORM 与 Silex 一起使用,但由于缺乏一致的文档,我发现这是一种完全令人沮丧的体验。 当我在控制台运行 vendor/bin/doctrine 时,我得到以下输出
我需要在 web.config 中的多个 WCF 服务中切换出一个 IP 地址。使用 web.config 转换,除了通过 xpath 指定每个地址之外,还有什么方法可以创建搜索和替换语句。例如。对于
我使用来自Ubuntu 14.04的tmux(tmux 1.8)。 我想通过~/.tmux.conf对其进行一些配置。但是无论我在该文件中设置的内容如何,tmux session 都相同。然后,我
嗨,我正在尝试将我的域别名重定向到一个域。 我目前有这个规则 当别名前面没有 www 时它工作得很好.. 我怎么说重定向所有不等于这个域的 谢
我的 Web 配置中有以下 XML,在 Release模式下,我需要根据其子项的名称属性删除 dependentAssembly 部分:assemblyIdentity。我在这里尝试了答案:xdt t
我正在为 web.config 文件寻找一个轻量级的文本编辑器,它具有颜色语法突出显示(如在 Visual Studio 中)。 有什么建议? 最佳答案 您可以使用 Notepad++ .当您使用 w
ImagePicker This plugin allows selection of multiple images from the camera roll
ImagePicker This plugin allows selection of multiple images from the camera roll
如果我有一个 Web 应用程序(有它自己的 web.config )和一个它使用的 .dll 恰好有它自己的 app.config 发生冲突时哪个设置文件会胜出? 最佳答案 不,您不会有任何冲突,因为
问题描述: 我正在尝试在 bash 脚本中使用终止符,但我不断收到一条错误消息,指出没有这样的文件或目录:~/.config/terminator/config .并防止终端在屏幕上弹出。但是,当我在
我是一名优秀的程序员,十分优秀!