fix: 网关完善

This commit is contained in:
2026-04-03 16:14:47 +08:00
parent be792ff35d
commit a76a772381
5 changed files with 28 additions and 47 deletions

View File

@@ -17,24 +17,20 @@
<java.version>17</java.version>
</properties>
<dependencies>
<!-- OpenFeign必须用于调用远程服务 -->
<!-- Spring Cloud Gateway3.x官方网关 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- Nacos 服务发现 -->
<!-- Nacos注册 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- 负载均衡3.x必须加 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.nl</groupId>
<artifactId>finnace-api</artifactId>
<version>${project.version}</version>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
</dependencies>

View File

@@ -2,10 +2,8 @@ package org.nl.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableFeignClients(basePackages = {"org.nl.finnaceapi.feignApi"}) // 扫描 Feign 接口
public class GatewayApplication {
public static void main(String[] args) {

View File

@@ -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();
}
}

View File

@@ -2,9 +2,18 @@ server:
port: 8012
spring:
application:
name: gateway-server
cloud:
nacos:
discovery:
server-addr: localhost:8848
namespace: public
enabled: true
gateway:
routes:
- id: user-route
uri: lb://user-service
predicates: Path=/user/**
- id: order-route
uri: lb://finnace-server
predicates: Path=/finnace/**

View File

@@ -1,13 +1,13 @@
package org.nl.gateway;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class GatewayApplicationTests {
@Test
void contextLoads() {
}
}
//package org.nl.gateway;
//
//import org.junit.jupiter.api.Test;
//import org.springframework.boot.test.context.SpringBootTest;
//
//@SpringBootTest
//class GatewayApplicationTests {
//
// @Test
// void contextLoads() {
// }
//
//}