注册服务安全机制
在微服务中,注册服务使用安全机制
注册服务
security:
basic:
enabled: true
user:
name: 888888 # 用户名
password: 888888 # 用户密码
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_DEFAULT_ZONE:http://888888:888888@localhost:8700/eureka/}
客户端需引入的插件
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
当时自己做时还遇到了个问题,org.springframework.cloud插件引入不了,
后续解决方法:添加版本
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
yml文件配置:
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_DEFAULT_ZONE:http://888888:888888@localhost:8700/eureka/}
启动类添加
@SpringBootApplication
@EnableEurekaClient
在yml文件与properties文件中注册方式的写法
eureka.client.service-url.defaultZone=http://888888:888888@localhost:8700/eureka/ #注册服务
spring.application.name=hmobilemedium #服务名称
eureka.instance.prefer-ip-address=true #注册到Eureka Server上的是