设为首页 加入收藏

TOP

springcloud用法(一)
2019-09-26 18:14:17 】 浏览:240
Tags:springcloud 用法

 

springcloud用法

 

 

使用springcloud搭建微服务肯定要在父工程下面编写子工程

 

一.搭建eureka注册中心

 

1.    创建maven项目(在springboot项目下建立子工程eureka-server)

 

2.    导入坐标

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>
</dependencies>

 

3.    创建引导类

 

@SpringBootApplication
@EnableEurekaServer  //添加注解 表名服务,声明这个应用时EurekaServer
public class EurekaManager {
    public static void main(String[] args) {
        SpringApplication.run(EurekaManager.class,args);
    }
}

 

 

4.    编写配置文件

编写application.yml文件

server:
  port:
10086
spring:
  application:
    name:
eureka-server  #自己注册的serviceId,即注册名称

eureka:
  client:
    service-url:
      defaultZone:
http://127.0.0.1:10086/eureka

    register-with-eureka: true   #注册自己,默认为true
   
fetch-registry: true  #拉取服务,默认为true

 

 

5.    效果截图

 

 

 

 

二.搭建提供者,user-service

提供者user-service对于注册中心而言还是客户端

1.    创建maven工程user-service

2.    导入坐标

 

 

<!--添加坐标-->
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>

    <dependency>
        <groupId>tk.mybatis</groupId>
        <artifactId>mapper-spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>

</dependencies>

 

 

3.    编写启动类

 

package com.ahd;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
impor
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 1/12/12
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇java使用face++简单实现人脸识别.. 下一篇spring与logstash整合,并将数据..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目