spring Cloud与Docker微服务架构实战笔记

Linux修改主机名方法:

         vi /etc/hosts 

然后修改 127.0.0.1  localhost localhost.localdomain 

可替换为 127.0.0.1 localhost peer1 peer2

这样就吧主机名字替换为 peer1 peer2 了。

然后使用  /etc/init.d/network restart 重启接口便可以生效。

在配置zuul时,提示报错HttpException: 没有到主机的路由    上网查得需要关闭linux防火墙,但是关闭掉防火墙后仍然报这个错误,     

//    @Scheduled(fixedDelay = 1000 * 60 * 30)
//    @PostConstruct
    private void getTokens() {
        String result2 = HttpRequest.post("http://10.20.30.40:5000/v3/auth/tokens")
                //超时,毫秒
                .body("{\n" +
                        "    \"auth\": {\n" +
                        "        \"identity\": {\n" +
                        "            \"methods\": [\n" +
                        "                \"password\"\n" +
                        "            ],\n" +
                        "            \"password\": {\n" +
                        "                \"user\": {\n" +
                        "                    \"name\": \"hanlp123\",\n" +
                        "                    \"domain\": {\n" +
                        "                        \"name\": \"Default\"\n" +
                        "                    },\n" +
                        "                    \"password\": \"Dksou@2020\"\n" +
                        "                }\n" +
                        "            }\n" +
                        "        },\n" +
                        "        \"scope\": {\n" +
                        "             \"project\": {\n" +
                        "             \t\"domain\": {\n" +
                        "                        \"name\": \"Default\"\n" +
                        "                    },\n" +
                        "                \"name\": \"hanlp\"\n" +
                        "            }\n" +
                        "        }\n" +
                        "    }\n" +
                        "}\n")
                .timeout(20000)
                .execute().header("x-subject-token");
        tokens = result2;
    }

//    @Scheduled(fixedDelay = 1000 * 60 * 30)
//    @PostConstruct

这两行注解注释以后系统启动成功。

 

java 定时任务之一 @Scheduled注解(第一种方法)

被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器执行一次。PostConstruct在构造函数之后执行,init()方法之前执行。PreDestroy()方法在destroy()方法知性之后执行

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值