热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

springCloud2.0配置eureka和zuul

eureka服务器配置pom.xml

eureka服务器 配置

pom.xml

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.jinlin
service-zuul
0.0.1-SNAPSHOT


org.springframework.boot
spring-boot-starter-parent
2.0.0.RELEASE


UTF-8
UTF-8
1.8



org.springframework.cloud
spring-cloud-config-server


org.springframework.boot
spring-boot-starter-test
test


org.springframework.cloud
spring-cloud-starter-netflix-eureka-server


org.springframework.cloud
spring-cloud-starter-netflix-zuul


org.springframework.boot
spring-boot-starter-web




org.springframework.cloud
spring-cloud-dependencies
Finchley.SR2
pom
import






org.springframework.boot
spring-boot-maven-plugin




spring-milestones
Spring Milestones
https://repo.spring.io/milestone

false



 

application.yml

server:
  port: 8888
eureka:
  instance:
    hostname: localhost
client:
  registerWithEureka: false
  fetchRegistry: false
  serviceUrl:
    defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
spring:
  application:
  name: service-zuul
zuul:
  routes:
  api-a:
    path: /api-member/**
    url: http://localhost:8081/
  api-b:
    path: /api-order/**
    # service-id: service-order
    url: http://localhost:8763/

启动类

package com.jinlin;

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;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@SpringBootApplication
@EnableEurekaServer
@EnableZuulProxy
public class AppZuul {

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

}

 

eureka客户端

pom.xml同上

application.yml

eureka:
  client:
  serviceUrl:
  defaultZone: http://localhost:8888/eureka/
server:
  port: 8763
spring:
  application:
    name: service-order

 

controller类和启动

package com.jinlin.controller;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableEurekaClient
@EnableAutoConfiguration
public class OrderController {

  @RequestMapping("/orderService")
  public String orderService() {
    return "aaaaa";
  }

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

 

转:https://www.cnblogs.com/jinlin-2018/p/9883433.html



推荐阅读
author-avatar
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有