2017-01-03 75 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 

這是行得通的。

相關問題