【发布时间】:2019-02-15 21:06:21
【问题描述】:
我刚刚开始通过 Spring Cloud 学习微服务,并开始尝试重现这篇文章 https://spring.io/blog/2015/07/14/microservices-with-spring 中的基本示例。这是我的代码:
尤里卡服务器
@SpringBootApplication
@EnableEurekaServer
public class ServiceRegistryApplication {
public static void main(String[] args) {
System.setProperty("spring.config.name", "registration-server");
SpringApplication.run(ServiceRegistryApplication.class, args);
}
}
资源/registration-server.yml:
# Configure this Discovery Server
eureka:
instance:
hostname: localhost
client: # Not a client, don't register with yourself (unless running
# multiple discovery servers for redundancy)
registerWithEureka: false
fetchRegistry: false
server:
port: 1111 # HTTP (Tomcat) port
示例服务:
@SpringBootApplication
@EnableDiscoveryClient
public class AccountsServiceApplication {
public static void main(String[] args) {
System.setProperty("spring.config.name", "accounts-server");
SpringApplication.run(AccountsServiceApplication.class, args);
}
}
accounts-service.yml:
# Spring properties
spring:
application:
name: accounts-service
# Discovery Server Access
eureka:
client:
serviceUrl:
defaultZone: http://localhost:1111/eureka/
# HTTP Server
server:
port: 2222 # HTTP (Tomcat) port
但是当我运行这两个应用程序并转到 localhost:1111 时,我在应用程序列表中看不到我的服务:
你能告诉我我做错了什么吗?
编辑
【问题讨论】:
-
account-server!=account-service所以基本上你的配置会被忽略。 -
请粘贴两个应用的服务器日志。
-
很难说没有看到更多的应用程序(依赖项以及日志)。博客在这里有代码github.com/paulc4/microservices-demo你能发现任何区别吗?