Spring Cloud微服务入门
    		       		warning:
    		            这篇文章距离上次修改已过417天,其中的内容可能已经有所变动。
    		        
        		                
                在Spring Cloud微服务中,我们可以使用Eureka作为服务注册中心,以下是一个简单的Eureka Server配置示例:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
 
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}在application.properties或application.yml中配置Eureka Server:
# application.yml
server:
  port: 
 
eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/这个Eureka Server应用将运行在8761端口,其他微服务可以通过该服务进行注册和发现。
评论已关闭