+spring gateway example
This commit is contained in:
parent
6cb4847bc8
commit
a6d298282a
34
Java/spring/gateway/build.gradle
Normal file
34
Java/spring/gateway/build.gradle
Normal file
@ -0,0 +1,34 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.1.4'
|
||||
id 'io.spring.dependency-management' version '1.1.3'
|
||||
}
|
||||
|
||||
group = 'example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
|
||||
java {
|
||||
sourceCompatibility = '17'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
ext {
|
||||
set('springCloudVersion', "2022.0.4")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
1
Java/spring/gateway/settings.gradle
Normal file
1
Java/spring/gateway/settings.gradle
Normal file
@ -0,0 +1 @@
|
||||
rootProject.name = 'gateway'
|
@ -0,0 +1,26 @@
|
||||
package example.gateway;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.gateway.route.builder.*;
|
||||
import org.springframework.cloud.gateway.route.*;
|
||||
import org.springframework.context.annotation.*;
|
||||
|
||||
@SpringBootApplication
|
||||
public class GatewayApplication {
|
||||
@Bean
|
||||
public RouteLocator rl(RouteLocatorBuilder builder) {
|
||||
return builder.routes()
|
||||
.route("netcat-1", r -> r.path("/cat1")
|
||||
.uri("http://127.0.0.1:8081")
|
||||
)
|
||||
.route("netcat-2", r -> r.path("/cat2")
|
||||
.uri("http://127.0.0.1:8082")
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GatewayApplication.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
spring:
|
||||
cloud:
|
||||
gateway:
|
||||
routes:
|
||||
- id: nc-1
|
||||
uri: https://localhost:8081
|
@ -0,0 +1,13 @@
|
||||
package example.gateway;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class GatewayApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user