【汇智学堂】微服务-SpringCloud创建生产者一

在这里插入图片描述
新建一项目:
在这里插入图片描述
填写项目名称等后:
在这里插入图片描述

修改pom.xml中的部分内容,maven导入:
在这里插入图片描述

在这里插入代码片在这里插入图片描述
application.yml:

server:
  port: 8762
spring:
  application:
    name: provider
eureka:
  client:
    service-url:
      defualtZone: http://localhost:8761/eureka/

TestController的内容

package com.huizhi.demo2.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @RequestMapping("/test")
    public String test(){
        return System.currentTimeMillis() + ":provider一号";
    }

}

启动项目Demo2Application的content:

package com.huizhi.demo2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableDiscoveryClient

public class Demo2Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo2Application.class, args);
    }

}

运行,先运行Server,再运行生产者。

发布了268 篇原创文章 · 获赞 47 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_39593940/article/details/103829569