fix: 网关完善
This commit is contained in:
@@ -17,24 +17,20 @@
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- OpenFeign(必须,用于调用远程服务) -->
|
||||
<!-- Spring Cloud Gateway(3.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>
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
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/**
|
||||
@@ -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() {
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user