zhouchaogithub / spring-cloud

SpringCloud学习项目
0 stars 0 forks source link

服务注册注意事项 #3

Open zhouchaogithub opened 6 years ago

zhouchaogithub commented 6 years ago

服务发现组件会通过一些机制定时检测已注册的服务,如果发现某服务无法访问了(可能是某几个心跳周期后),就将该服务从服务注册表中移除。一般是服务消费者向注册中心发送3次心跳,如果服务无法访问了,则从服务注册表中剔除该服务

spring boot 2 使用 actuator 404的问题: 按照 actuator 的使用方法,项目中添加下面的依赖。

org.springframework.boot spring-boot-starter-actuator http://localhost:9000/health 返回错误404.

原因是2.0的将所有的端点都屏蔽了

解决办法:

1.降低springboot版本的比如 1.4.3 1.5.4 等

所有 endpoints 默认情况下都已移至 /actuator。就是多了跟路径 actuator ; 例: 但是Actuator只暴露了health和info端点。

解决: 在SpringBoot的application.yml配置文件中加入这句话暴露所有端点。

management: endpoints: web: exposure: include: "" # 在yaml 文件属于关键字,所以需要加引号 但是http://localhost:8000/actuator/autoconfig 会报错404。原因是/autoconfig重命名为/conditions

附录:

配置健康检查相关配置项 eureka.client.healthcheck.enabled=true managerment.security.enabled=false management.endpoints.health.sensitive=false #配置健康检查的服务端口(可以不用配置) #management.server.port=5333 #暴露出所有端点 management.endpoints.web.exposure.include=*

zhouchaogithub commented 6 years ago

高版本中Eureka服务端添加security认证时除了添加security依赖还需要去除csrf过滤和添加认证配置,否则不成功 @Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.csrf() .disable(); http.authorizeRequests() .anyRequest() .authenticated() .and() .httpBasic();//开启认证 }