springcloud (three): Eureka client producers, consumers and feign use

Eureka server segment using springcloud eureka_service (II) in

A registry because the use of a server-side, n clients: producer client, consumer client .... all the best way is through the client object to pass parameters, you need to create a common component project for the convenience of clients pass value n

 

Second, create a public component project

1. Create a common component projects, because it is only shared class data transport layer, thus creating a normal maven like project

 

2. Give the project a name common components

 

 3.maven configuration

 

4. Similarly, in order to better access to a window, we created a separate project module

 

5. Create the following project structure

 

6. Edit Classes.java class

package cn.kgc.vo;

import java.io.Serializable;

/**
 * Created by Administrator on 2019/6/11.
 */
public class Classes implements Serializable{
    private Integer cid;
    private String cname;

    public Classes() {
    }

    public Classes(Integer cid, String cname) {
        this.cid = cid;
        this.cname = cname;
    }

    public Integer getCid() {
        return cid;
    }

    public void setCid(Integer cid) {
        this.cid = cid;
    }

    public String getCname() {
        return cname;
    }

    public void setCname(String cname) {
        this.cname = cname;
    }

    @Override
    public String toString() {
        return "Classes{" +
                "cid=" + cid +
                ", cname='" + cname + '\'' +
                '}';
    }
}

 

7编辑Student.java类

package cn.kgc.vo;

import java.io.Serializable;

/**
 * Created by Administrator on 2019/6/11.
 */
public class Student implements Serializable{
    private Integer sid;
    private String sname;
    private String password;
    private String subject;
    private Double result;
    private Integer cid;

    public Student() {
    }

    public Student(Integer sid, String sname, String password, String subject, Double result, Integer cid) {
        this.sid = sid;
        this.sname = sname;
        this.password = password;
        this.subject = subject;
        this.result = result;
        this.cid = cid;
    }

    public Integer getSid() {
        return sid;
    }

    public void setSid(Integer sid) {
        this.sid = sid;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public Double getResult() {
        return result;
    }

    public void setResult(Double result) {
        this.result = result;
    }

    public Integer getCid() {
        return cid;
    }

    public void setCid(Integer cid) {
        this.cid = cid;
    }

    @Override
    public String toString() {
        return "Student{" +
                "sid=" + sid +
                ", sname='" + sname + '\'' +
                ", password='" + password + '\'' +
                ", subject='" + subject + '\'' +
                ", result=" + result +
                ", cid=" + cid +
                '}';
    }

}

 

8.因为在企业中 项目都是独立调用的,也就意味着其他eureka客户端会互相调用,会公共引用公共组件的类,那么独立的项目引用的方式就是 将公共组件项目使用maven打成jar包或war包,存入maven仓库,供所有人公共调用,因此我们下面使用现有的idea工具将项目打成war包,打入我们自己的maven仓库,如果是在企业中,则将项目达到公共私服的maven库中,

注意:使用idea中将项目打成war包存入maven仓库时,一定一定注意 在idea中已经配置过自己的maven本地仓库地址

 

 

看到此处我们的公共组件就已经打成jar文件

 

三、创建eureka生产者项目

1.创建项目模块

 

2. 选择项目类型

 

3.输入groupId 和模块名称

 

4.选择创建web、sql、spring cloud discovery

 

 5. 选择模块名称

 

Guess you like

Origin www.cnblogs.com/holly8/p/11002943.html