【问题标题】:server.port in command line not working with spring cloud config server and eureka server命令行中的 server.port 不能与 spring cloud config server 和 eureka server 一起使用
【发布时间】:2017-05-17 04:46:32
【问题描述】:

我正在研究弹簧罐。我现在拥有的是spring cloud config server和eureka server。

配置服务器代码

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

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

application.properties

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-boot spring-cloud netflix-eureka


【解决方案1】:
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
server.port=1111
spring.cloud.config.allowOverride=true
spring.cloud.config.overrideNone=true
spring.cloud.config.overrideSystemProperties=false

这是有效的。

【讨论】:

    【解决方案2】:

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

    还有allow overrides的选项。

    由 引导上下文通常是“远程的”(例如来自配置服务器),并且 默认情况下,它们不能在本地被覆盖,除了命令 线。如果您想允许您的应用程序覆盖远程 具有自己的系统属性或配置文件的属性, 远程属性源必须通过设置授予它权限 spring.cloud.config.allowOverride=true(设置这个不行 本地)。一旦设置了该标志,就会有一些更细粒度的设置 控制与系统相关的远程属性的位置 属性和应用程序的本地配置: spring.cloud.config.overrideNone=true 覆盖任何本地 财产来源,以及 spring.cloud.config.overrideSystemProperties=false 如果只有系统 属性和环境变量应该覆盖远程设置,但不是 本地配置文件。

    【讨论】:

    猜你喜欢
    • 2020-11-04
    • 2017-11-28
    • 2015-09-08
    • 2017-02-06
    • 2016-05-12
    • 1970-01-01
    • 2019-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多