vin*_*ent 4 spring-boot spring-cloud netflix-eureka
我正在研究春天可以.我现在拥有的是spring cloud配置服务器和eureka服务器.
配置服务器的代码
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
application.properties
spring.application.name=config-server
spring.cloud.config.server.git.uri=https://github.com/vincentwah/spring-cloud-config-repository/
server.port=7001
Run Code Online (Sandbox Code Playgroud)
Eureka服务器的代码
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
bootstrap.properties
spring.application.name=eureka-server
spring.cloud.config.uri=http://localhost:7001/
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
当我启动eureka服务器时,我想更改端口,所以我运行下面的命令
java -jar target/eureka-server-0.0.1-SNAPSHOT.jar --server.port=1234
Run Code Online (Sandbox Code Playgroud)
但是,服务器仍然使用端口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)
Run Code Online (Sandbox Code Playgroud)
我认为我在命令行中没有使用--server.port.有没有人遇到同样的问题?
默认情况下,Spring Cloud Config会覆盖本地配置.它应该是真理的来源.您可以使用配置文件,因此端口未使用特定配置文件定义.如果不是真的需要,你也可以禁用配置客户端(例如在测试中).
还有允许覆盖的选项.
由引导上下文添加到应用程序的属性源通常是"远程"(例如,来自Config服务器),并且默认情况下,除了命令行之外,它们不能在本地重写.如果要允许应用程序使用自己的系统属性或配置文件覆盖远程属性,则远程属性源必须通过设置授予其权限
spring.cloud.config.allowOverride=true(在本地设置此方法不起作用).设置该标志后,有一些更细粒度的设置来控制远程属性相对于系统属性和应用程序的本地配置的位置:spring.cloud.config.overrideNone=true覆盖任何本地属性源,spring.cloud.config.overrideSystemProperties=false如果只有系统属性和环境变量应覆盖远程设置,但不是本地配置文件.
| 归档时间: |
|
| 查看次数: |
1551 次 |
| 最近记录: |