【发布时间】: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 没有做错。有人遇到同样的问题吗?
【问题讨论】:
-
哪个操作系统?试试
--SERVER_PORT=1234。 -
Windows 7 + 春季启动 1.4.3 。我试过 --SERVER_PORT=1234 ,但没有用。我在github.com/vincentwah/spring-boot/tree/master/config-server 和github.com/vincentwah/spring-boot/tree/master/eureka-server 有源代码
-
刚刚注意到您从配置服务器检索属性...如果我没记错的话,这些属性确实优先于其他定义的属性。
-
正如docs.pivotal.io/spring-cloud-services/1-3/config-server/… 所述,“配置服务器的属性将覆盖本地定义的属性”。但是docs.spring.io/spring-boot/docs/current/reference/html/…也提到,“命令行属性总是优先于其他属性源”,所以如果我使用config server,那么没有办法动态更改server.port?
-
嗯...问题是
--server.port是命令行参数还是-Dserver.port。此外,Spring Cloud 在这里优先(Spring Boot 所做的一切基本上都属于本地定义的类别)。
标签: spring-boot spring-cloud netflix-eureka