初识SpringCloud,创建provider、consumer和eureka

项目包结构

在这里插入图片描述

provider

包结构

在这里插入图片描述

User

需要连接数据库,添加@Table和@Id注释

package com.xvyihj.pojo;

import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

@Table(name = "t_user")
public class User implements Serializable
{

    @Id
    private Long id;

    private String username;

    private String password;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

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

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}

application.yml

server:
  port: 8081
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/tb_user1?characterEncoding=utf-8&serverTimezone=Asia/Shanghai
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: 3314
  application:
    name: xvyihj-provider
mybatis:
  type-aliases-package: com.xvyihj.pojo
eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:10086/eureka

consumer

包结构

在这里插入图片描述

User

不连接数据库,无需注释

application.yml

server:
  port: 8084
eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:10086/eureka
spring:
  application:
    name: xvyihj-consumer

eureka

包结构

在这里插入图片描述

Application

添加@EnableEurekaServer注释

package com.xvyihj;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class XvyihjEurekaApplication
{

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

}

application.yml

server:
  port: 10086
eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:10086/eureka
spring:
  application:
    name: xvyihj-eureka
©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页