springcloud2.0 添加配置中心遇到的坑

新手入门,在springcloud 配置config的时候遇到了几个比较烦的坑

先说1.5x版本的一些配置吧

首先是端点暴露的方式

management:
  security:
    enabled: false

这个配置方式在2.0之后被淘汰了,换成了

management:
  endpoints:
    web:
      exposure:
     # * 代表所有暴露所有端点 include:
"*"

如果要多个暴露的话,需要用 ,隔开

其次是,关于刷新配置的接口,1.5x的时候用的路径是  http://ip:port/bus/refresh

2.0的时候!!!!它的路径变了, 当你用post请求  http://ip:port/bus/refresh 的时候它会提示你 不支持 POST方式!!

{
    "timestamp": "*********",
    "status": 405,
    "error": "Method Not Allowed",
    "message": "Request method 'POST' not supported",
    "path": "/bus/refresh"
}

然后我改成了GET方式请求,请求是成功了,但是配置文件并没有更新到(关键是这个get请求它成功了,开始还以为是配置有错),苦苦找寻,终于在 https://blog.csdn.net/weixin_39986856/article/details/83119858  找到了答案。

2.0的时候,路径改成了 http://ip:port/actuator/bus-refresh 替换成这个路径后,刷新配置成功!!

还有个坑是在添加 消息总线时,RabbitMQ遇到的坑

 

rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest

 

添加完这个配置后,确实是没问题,但是只能用localhost连接,当我换成其他ip地址的时候就不行了。

配置文件中有这么一段话,意思是允许任何ip访问时,请去掉注释。

  %% Uncomment the following line if you want to allow access to the
   %% guest user from anywhere on the network.
  %% {loopback_users, []},

 把它放开   {loopback_users, []},  即可。

最好还是重新建一个账号,不要使用guest

posted @ 2019-03-15 17:24  张左左  阅读(1676)  评论(0编辑  收藏  举报