fix: 网关完善
This commit is contained in:
@@ -17,24 +17,20 @@
|
|||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- OpenFeign(必须,用于调用远程服务) -->
|
<!-- Spring Cloud Gateway(3.x官方网关) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Nacos 服务发现 -->
|
<!-- Nacos注册 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- 负载均衡(3.x必须加) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.nl</groupId>
|
|
||||||
<artifactId>finnace-api</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,8 @@ package org.nl.gateway;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableFeignClients(basePackages = {"org.nl.finnaceapi.feignApi"}) // 扫描 Feign 接口
|
|
||||||
public class GatewayApplication {
|
public class GatewayApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
package org.nl.gateway;
|
|
||||||
|
|
||||||
import org.nl.finnaceapi.dto.Init;
|
|
||||||
import org.nl.finnaceapi.feignApi.FinanceFeignApi;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController()
|
|
||||||
@RequestMapping("/api")
|
|
||||||
public class InitController {
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FinanceFeignApi financeFeignApi;
|
|
||||||
|
|
||||||
@GetMapping("/gateway")
|
|
||||||
public Init getPlan(){
|
|
||||||
return financeFeignApi.init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,9 +2,18 @@ server:
|
|||||||
port: 8012
|
port: 8012
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
|
name: gateway-server
|
||||||
cloud:
|
cloud:
|
||||||
nacos:
|
nacos:
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: localhost:8848
|
server-addr: localhost:8848
|
||||||
namespace: public
|
namespace: public
|
||||||
enabled: true
|
enabled: true
|
||||||
|
gateway:
|
||||||
|
routes:
|
||||||
|
- id: user-route
|
||||||
|
uri: lb://user-service
|
||||||
|
predicates: Path=/user/**
|
||||||
|
- id: order-route
|
||||||
|
uri: lb://finnace-server
|
||||||
|
predicates: Path=/finnace/**
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
package org.nl.gateway;
|
//package org.nl.gateway;
|
||||||
|
//
|
||||||
import org.junit.jupiter.api.Test;
|
//import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
//import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
//
|
||||||
@SpringBootTest
|
//@SpringBootTest
|
||||||
class GatewayApplicationTests {
|
//class GatewayApplicationTests {
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
void contextLoads() {
|
// void contextLoads() {
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|||||||
Reference in New Issue
Block a user