右键demo_parent->new->Module->Maven,选择Module SK为jdk8->ArtifactId:demo_zuulmysql
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>demo_parent</artifactId> <groupId>com.demo</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>demo_zuul</artifactId> <dependencies>
<!-- 服务网关依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-zuul</artifactId> </dependency>
<!-- eureka客服端依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> </dependencies> </project>
server: port: 8888 spring: application: name: demo-zuul zuul: routes: # 配置路由 app: # 路由名称,这是一个标识做用,只要是[a-z]可随意,没有什么影响 path: /myarticle/* #匹配以/myarticle路径开头的全部路径 serviceId: demo-article #只要符合path规则,则转发到demo-article微服务 eureka: client: fetch-registry: true register-with-eureka: true service-url: defaultZone: http://127.0.0.1.181:7000/eureka #在IDEA中运行时使用127.0.0.1,部署发布时,请修改成虚拟机宿主机的ip地址 instance: prefer-ip-address: true
package com.demo.zuul; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.zuul.EnableZuulProxy; /** * 微服务网关 */ @SpringBootApplication // 标注启动zuul网关代理 @EnableZuulProxy // 标注eureka客户端 @EnableEurekaClient public class ZuulApplication { public static void main(String[] args) { SpringApplication.run(ZuulApplication.class, args); } }
刷新eureka界面,能够看到有一个名为DEMO-ZUUL的服务已经注册上来了spring
docker微服务部署之:4、安装docker、docker中安装mysql和jdk1.八、手动构建镜像、部署项目sql