springcloud下单机版的Eureka使用
服务注册中心
服务提供者
服务消费者
Eureka 服务注册发现中心配置
1、pom文件需要添加的依赖
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
注意spring-cloud-dependencies和springboot版本的兼容
2、application.properties下配置Eureka的配置属性
# 设置spring应用命名,可以自定义,非必要
spring.application.name=eureka-server
# 设置Eureka Server WEB控制台端口,自定义
server.port=8761
#是否将自己注册到Eureka-Server中,默认的为true(服务器自己就不注册自己了)
eureka.client.register-with-eureka=false
#是否从Eureka-Server中获取服务注册信息,默认为true
eureka.client.fetch-registry=false
3、启动类配置,添加 @EnableEurekaServer 注解
@EnableEurekaServer
@SpringBootApplication
public class SpringCloudEurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudEurekaServerApplication.class,args);
}
}
4、注册中心的安全认证(如果可以任意访问的话,那么其安全性太低)
1、添加依赖
org.springframework.boot
spring-boot-starter-security
引入依赖后后默认认证,再次访问 注册服务中心会要求登录
秘密是随机生成的UUID,启动时会显示在控制台。默认用户名是user
用户名和密码也可以在application.properties配置文件中配置
#安全验证
spring.security.user.name=liang
spring.security.user.password=123456
如果要禁用安全认证,可以在启动类中添加exclude = {SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class}
@EnableEurekaServer
@