1.环境配置
Java version:
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
springboot version: 2.0.1.RELEASE ;
spring-cloud version :Finchley.RELEASE;
maven version :Apache Maven 3.3.9
IDE工具:idea
【注意spring boot 与springcloud 的版本对应关系】
spring-boot-starter-parent | spring-cloud-dependencies | ||||
---|---|---|---|---|---|
版本号 | 发布日期 | 版本号 | 发布日期 | ||
1.5.2.RELEASE | 2017年3月 | 稳定版 | Dalston.RC1 | 2017年未知月 | |
1.5.9.RELEASE | 2017年11月 | 稳定版 | Edgware.RELEASE | 2017年11月 | 稳定版 |
1.5.16.RELEASE | Edgware.SR5 | ||||
1.5.20.RELEASE | Edgware.SR5 | ||||
Spring Boot >=2.0.0.M3 and <2.0.0.M5 | Finchley.M2 | ||||
Spring Boot >=2.0.0.M5 and <=2.0.0.M5 | Finchley.M3 | ||||
Spring Boot >=2.0.0.M6 and <=2.0.0.M6 | Finchley.M4 | ||||
Spring Boot >=2.0.0.M7 and <=2.0.0.M7 | Finchley.M5 | ||||
Spring Boot >=2.0.0.RC1 and <=2.0.0.RC1 | Finchley.M6 | ||||
Spring Boot >=2.0.0.RC2 and <=2.0.0.RC2 | Finchley.M7 | ||||
Spring Boot >=2.0.0.RELEASE and <=2.0.0.RELEASE | Finchley.M9 | ||||
Spring Boot >=2.0.1.RELEASE and <2.0.2.RELEASE | Finchley.RC1 | ||||
Spring Boot >=2.0.2.RELEASE and <2.0.3.RELEASE | Finchley.RC2 | ||||
Spring Boot >=2.0.3.RELEASE and <2.0.999.BUILD-SNAPSHOT | Finchley.SR4 | ||||
Spring Boot >=2.0.999.BUILD-SNAPSHOT and <2.1.0.M3 | Finchley.BUILD-SNAPSHOT | ||||
Spring Boot >=2.1.0.M3 and <2.1.0.RELEASE | Greenwich.M1 | ||||
Spring Boot >=2.1.0.RELEASE and <2.1.9.BUILD-SNAPSHOT | Greenwich.SR2 | ||||
Spring Boot >=2.1.9.BUILD-SNAPSHOT and <2.2.0.M4 | Greenwich.BUILD-SNAPSHOT | ||||
Spring Boot >=2.2.0.M4 and <=2.2.0.M5 | Hoxton.M2 | ||||
Spring Boot >=2.2.0.BUILD-SNAPSHOT | Hoxton.BUILD-SNAPSHOT | ||||
待更新... |
spring官方对应查看网址:https://start.spring.io/actuator/info
2.application.properties 配置
#服务端口号
server.port=9000
#服务名称
spring.application.name=gateway-server
#注册中心地址
eureka.client.serviceUrl.defaultZone=${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
management.endpoint.conditions.enabled=true
#优先使用IP地址注册
eureka.instance.prefer-ip-address=true
##服务所属分组名称
#eureka.instance.app-group-name=lkf_group
#服务实例id
eureka.instance.instanceId=${spring.application.name}@${spring.cloud.client.ip-address}@${server.port}
#开放所有页面节点 默认只开启了health、info两个节点
management.endpoints.web.exposure.include=*
#启用基于服务发现的路由定位
spring.cloud.gateway.discovery.locator.enabled=true
#启用服务实例id名称小写支持
spring.cloud.gateway.discovery.locator.lowerCaseServiceId=true
3.启动类
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
4.pom.xml
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dq.cloud</groupId>
<artifactId>dq-gateway</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
<!--构建配置-->
<build>
<resources>
<!--包括所有文件-->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
<!--拷贝conf配置文件-->
<resource>
<directory>deploy/conf</directory>
<includes>
<include>*.properties</include>
<include>logback.xml</include>
</includes>
<targetPath>${project.build.directory}/${artifactId}/conf</targetPath>
<filtering>true</filtering>
</resource>
<!--拷贝bin运行文件-->
<resource>
<directory>deploy/bin</directory>
<includes>
<include>*.sh</include>
</includes>
<targetPath>${project.build.directory}/${artifactId}/bin</targetPath>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${artifactId}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<excludes>
<exclude>*.properties</exclude>
<exclude>logback.xml</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>jar-package</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${artifactId}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<filters>
<filter>deploy/env/application-dev.properties</filter>
</filters>
</build>
</profile>
<profile>
<id>test</id>
<build>
<filters>
<filter>deploy/env/application-test.properties</filter>
</filters>
</build>
</profile>
</profiles>
</project>