SpringCloud之eureka

搭建eureka注册中心的服务端步骤:

1.添加eureka依赖

  <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>

2.添加注解@EnableEurekaServer

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
@EnableEurekaServer
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class);
}
}

3.配置application.yml/application.propeties文件

server:
port: 8082

spring:
application:
name: eureka-server
eureka:
client:
service-url:
#defaultZone:http:// eureka.instance.hostname:{eureka.instance.hostname} :{server.port} /eureka/
defaultZone: http://127.0.0.1:8082/eureka/

创建服务提供者

1.添加依赖

org.springframework.cloud spring-cloud-netflix-eureka-client

2.添加注解@EnableDiscoveryClient

@EnableDiscoveryClient
@SpringBootApplication
public class SpringPlication {
public static void main(String[] args) {
SpringApplication.run(SpringPlication.class);
}
}

3.添加配置

同上面所示

注:
如果在Springboot项目中没有数据库的相关配置,要在SpringBootApplication注解中增加属性
exclude= {DataSourceAutoConfiguration.class}

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 数字20 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读