gpt4 book ai didi

spring-boot - 命令行中的 server.port 不适用于 Spring Cloud 配置服务器和 eureka 服务器

转载 作者:行者123 更新时间:2023-12-05 00:16:42 26 4
gpt4 key购买 nike

我正在研究 Spring 可​​以。我现在拥有的是 Spring Cloud 配置服务器和 eureka 服务器。

配置服务器的代码

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}

应用程序属性
spring.application.name=config-server
spring.cloud.config.server.git.uri=https://github.com/vincentwah/spring-cloud-config-repository/
server.port=7001

Eureka 服务器的代码
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}

bootstrap.properties
spring.application.name=eureka-server
spring.cloud.config.uri=http://localhost:7001/

eureka-server 的配置是 https://github.com/vincentwah/spring-cloud-config-repository/blob/master/eureka-server.properties
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
server.port=1111

当我启动 eureka 服务器时,我想更改端口,所以我运行以下命令
java -jar target/eureka-server-0.0.1-SNAPSHOT.jar --server.port=1234

但是,服务器仍然以端口 1111 启动
2017-01-03 14:04:11.324  INFO 6352 --- [      Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl    : Changing status to UP
2017-01-03 14:04:11.339 INFO 6352 --- [ Thread-10] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
2017-01-03 14:04:11.492 INFO 6352 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 1111 (http)
2017-01-03 14:04:11.493 INFO 6352 --- [ main] c.n.e.EurekaDiscoveryClientConfiguration : Updating port to 1111
2017-01-03 14:04:11.500 INFO 6352 --- [ main] com.example.EurekaServerApplication : Started EurekaServerApplication in 27.532 seconds (JVM running for 29.515)

我认为我在命令行中使用 --server.port 并没有错。有人遇到同样的问题吗?

最佳答案

默认情况下,Spring Cloud Config 会覆盖本地配置。它旨在成为真理的来源。您可以使用配置文件,以便不使用特定配置文件定义端口。如果不是真的需要(例如在测试中),您也可以禁用配置客户端。

allow overrides也有选项.

The property sources that are added to you application by the bootstrap context are often "remote" (e.g. from a Config Server), and by default they cannot be overridden locally, except on the command line. If you want to allow your applications to override the remote properties with their own System properties or config files, the remote property source has to grant it permission by setting spring.cloud.config.allowOverride=true (it doesn’t work to set this locally). Once that flag is set there are some finer grained settings to control the location of the remote properties in relation to System properties and the application’s local configuration: spring.cloud.config.overrideNone=true to override with any local property source, and spring.cloud.config.overrideSystemProperties=false if only System properties and env vars should override the remote settings, but not the local config files.

关于spring-boot - 命令行中的 server.port 不适用于 Spring Cloud 配置服务器和 eureka 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41437644/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com