2017-01-03 78 views
3

我正在学习spring可以。我现在拥有的是一个Spring云配置服务器和eureka服务器。server.port在命令行中不能与Spring云配置服务器和尤里卡服务器一起工作

代码配置服务器

@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 

代码尤里卡服务器

@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/ 

尤里卡服务器的配置是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 

当我开始尤里卡服务器,我想更改端口,所以我下面的命令来运行

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。有人遇到同样的问题吗?

+0

哪个操作系统?试试'--SERVER_PORT = 1234'。 –

+0

Windows 7 +弹簧启动1.4.3。我试过了--SERVER_PORT = 1234,但没有工作。我有https://github.com/vincentwah/spring-boot/tree/master/config-server和https:// github上的源代码。com/vincentwah/spring-boot/tree/master/eureka-server – vincent

+0

只要注意到你从配置服务器上检索属性......如果我正确地记得那些优先于其他定义的属性。 –

回答

2

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

也有allow overrides的选项。

了由 引导上下文添加到你的应用程序的属性来源往往是“远程”(例如,从配置服务器),和 默认情况下它们不能在本地覆盖,除了在命令 线。如果您希望允许应用程序使用其自己的系统属性或配置文件覆盖远程 属性,则 远程属性源必须通过设置 spring.cloud.config.allowOverride=true(它不能在本地设置此 )来授予其权限。一旦该标志被设置有一些更细致的设置 控制远程属性的位置相对于系统 性能和应用程序的本地配置: spring.cloud.config.overrideNone=true任何地方 财产来源覆盖,并 spring.cloud.config.overrideSystemProperties=false如果只是系统 属性和环境变量应该覆盖远程设置,但不包括本地配置文件 。

0
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 

这是行得通的。

相关问题