我正在研究春季罐头。我现在拥有的是spring云配置服务器和eureka服务器。
配置服务器代码
@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服务器的配置为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。有人遇到同样的问题吗?
默认情况下,Spring Cloud Config覆盖本地配置。它是真理的源泉。您可以使用配置文件,这样端口就不会用特定的配置文件定义。如果不是真的需要配置客户端(例如在测试中),您也可以禁用它。
也有允许重写的选项。
由引导程序上下文通常是"远程"的(例如,从配置服务器),并且默认情况下,它们不能在本地重写,除非在命令上线如果要允许应用程序覆盖远程属性及其自己的系统属性或配置文件远程属性源必须通过设置授予它权限
spring.cloud.config.allowOverride=true
(设置此项不起作用本地)。一旦设置了该标志,就会有一些更细粒度的设置控制远程属性相对于系统的位置属性和应用程序的本地配置:spring.cloud.config.overrideNone=true
用任何本地财产来源,以及spring.cloud.config.overrideSystemProperties=false
如果仅系统属性和env-var应该覆盖远程设置,但不能本地配置文件。
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
这是有效的。