SpringBoot实现Eureka注册功能
2018-01-23 00:00
555 查看
一、新建两个子模块,我这边的命名Eureka和Client,在父级的pom.xml
二、在Eureka中新建package、Application服务需要在包下才能正常加载启动,根目录下启动会报异常
Eureka下的application.yml
三、Client下新建package和Application
Client下application.yml
<!-- 集成web方式的开发 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- 服务与注册中心 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency>
二、在Eureka中新建package、Application服务需要在包下才能正常加载启动,根目录下启动会报异常
package eureka; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @SpringBootApplication @EnableEurekaServer --作为服务端注解 public class EurekaServer { public static void main(String[] args) { new SpringApplicationBuilder(EurekaServer.class).web(true).run(args); } }
Eureka下的application.yml
server: port: 9001 eureka: instance: hostname: localhost prefer-ip-address: true client: register-with-eureka: false #不作为服务注册 fetch-registry: false #单点服务不需要同步其他服务数据 service-url: defaultZone: http://localhost:9001/eureka/ #服务注册地址
三、Client下新建package和Application
package redis; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableEurekaClient --作为客户端注解 public class RedisServer { public static void main(String[] args) { new SpringApplicationBuilder(RedisServer.class).web(true).run(args); } }
Client下application.yml
server: port: 9009 spring: application: name: springCloud-redis eureka: instance: hostname: localhost client: register-with-eureka: true fetch-registry: false service-url: defaultZone: http://localhost:9001/eureka/[/code] 四、启动Eureka、Client,浏览器访问http://localhost:9001
相关文章推荐
- SpringBoot+thymeleaf简单实现登陆注册及记账功能
- (二)SpringBoot+SpringCloud —— 使用Eureka实现服务注册与发现
- 通过Eureka、DiscoveryClient实现Spring Boot Admin管理功能
- SpringBoot实现简单的注册与登陆功能
- Spring Boot实现邮件注册功能示例代码
- 基于spring boot的mysql使用pagehelper实现分页功能
- SpringMVC/SpringBoot使用easypoi实现Excel文件导入导出功能实现
- Spring+MongoDB实现登录注册功能
- spring boot MVC 三 用户注册和登录的实现
- Spring cloud eureka+Client+Spring boot admin 服务注册监控
- eureka(注册中心)中spring-boot-starter-actuator监控
- 基于spring-cloud实现eureka注册服务小案例
- Spring Boot使用Netty SocketIO实现WebIM功能
- SpringBoot WebSocket 实现简单的聊天功能
- 在Spring Boot框架下使用WebSocket实现聊天功能
- SpringBoot+layui实现文件上传功能
- SpringBoot 集成Kaptcha实现验证码功能实例详解
- Spring Boot入门(12)实现页面访问量统计功能
- spring boot实现图片的上传和下载功能
- springboot 实现邮件发送功能