引入SpringCloudGateway
This commit is contained in:
parent
d0ec8f97fc
commit
53558cc55e
|
|
@ -0,0 +1,70 @@
|
||||||
|
<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>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.qihang</groupId>
|
||||||
|
<artifactId>qihang-oms</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>api</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>api</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>17</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<spring-boot.version>3.0.2</spring-boot.version>
|
||||||
|
<spring-cloud-alibaba.version>2022.0.0.0</spring-cloud-alibaba.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||||
|
<!-- <artifactId>spring-boot-starter</artifactId>-->
|
||||||
|
<!-- <version>${spring-boot.version}</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
<version>${spring-cloud-alibaba.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.springframework.cloud</groupId>-->
|
||||||
|
<!-- <artifactId>spring-cloud-starter</artifactId>-->
|
||||||
|
<!-- <version>4.0.0</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||||
|
<version>4.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>junit</groupId>-->
|
||||||
|
<!-- <artifactId>junit</artifactId>-->
|
||||||
|
<!-- <version>4.13.2</version>-->
|
||||||
|
<!-- <scope>test</scope>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
</dependencies>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||||
|
<version>${spring-cloud-alibaba.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.qihang.api;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hello world!
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@SpringBootApplication
|
||||||
|
public class Api
|
||||||
|
{
|
||||||
|
public static void main( String[] args )
|
||||||
|
{
|
||||||
|
System.out.println( "Hello World! Api" );
|
||||||
|
SpringApplication.run(Api.class, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
server:
|
||||||
|
port: 8080
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: api-service
|
||||||
|
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
server-addr: 127.0.0.1:8848
|
||||||
|
username: nacos
|
||||||
|
password: nacos
|
||||||
|
gateway:
|
||||||
|
discovery:
|
||||||
|
locator:
|
||||||
|
enabled: true
|
||||||
|
routes:
|
||||||
|
- id: tao_oms_route
|
||||||
|
uri: lb://tao-oms # lb 表示从 nacos 中按照名称获取微服务,并遵循负载均衡策略,user-service 对应用户微服务应用名
|
||||||
|
predicates:
|
||||||
|
- Path=/tao-api/** # 使用断言
|
||||||
|
filters:
|
||||||
|
- StripPrefix=1 # 使用过滤器
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.qihang;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for simple App.
|
||||||
|
*/
|
||||||
|
public class AppTest
|
||||||
|
extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the test case
|
||||||
|
*
|
||||||
|
* @param testName name of the test case
|
||||||
|
*/
|
||||||
|
public AppTest( String testName )
|
||||||
|
{
|
||||||
|
super( testName );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the suite of tests being tested
|
||||||
|
*/
|
||||||
|
public static Test suite()
|
||||||
|
{
|
||||||
|
return new TestSuite( AppTest.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rigourous Test :-)
|
||||||
|
*/
|
||||||
|
public void testApp()
|
||||||
|
{
|
||||||
|
assertTrue( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -83,7 +83,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
<!-- <groupId>org.springframework.cloud</groupId>-->
|
<!-- <groupId>org.springframework.cloud</groupId>-->
|
||||||
<!-- <artifactId>spring-cloud-loadbalancer</artifactId>-->
|
<!-- <artifactId>spring-cloud-starter-gateway</artifactId>-->
|
||||||
<!-- <version>4.0.0</version>-->
|
<!-- <version>4.0.0</version>-->
|
||||||
<!-- </dependency>-->
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import org.springframework.web.client.RestTemplate;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@EnableFeignClients(basePackages = "com.qihang.oms.api")
|
@EnableFeignClients(basePackages = "com.qihang.oms.api")
|
||||||
//@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@ComponentScan(basePackages={"com.qihang"})
|
@ComponentScan(basePackages={"com.qihang"})
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class Api
|
public class Api
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
//package com.qihang.oms.api.config;
|
||||||
|
//
|
||||||
|
//import org.springframework.context.annotation.Bean;
|
||||||
|
//import org.springframework.context.annotation.Configuration;
|
||||||
|
//import org.springframework.http.codec.ServerCodecConfigurer;
|
||||||
|
//import org.springframework.http.codec.json.Jackson2JsonDecoder;
|
||||||
|
//import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||||
|
//import org.springframework.web.reactive.config.WebFluxConfigurer;
|
||||||
|
//
|
||||||
|
//@Configuration
|
||||||
|
//public class WebConfig {
|
||||||
|
// @Bean
|
||||||
|
// public ServerCodecConfigurer serverCodecConfigurer() {
|
||||||
|
// return ServerCodecConfigurer.create();
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
cloud:
|
cloud:
|
||||||
loadbalancer:
|
loadbalancer:
|
||||||
|
|
@ -8,6 +7,12 @@ spring:
|
||||||
serverAddr: 127.0.0.1:8848
|
serverAddr: 127.0.0.1:8848
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: 127.0.0.1:8848
|
server-addr: 127.0.0.1:8848
|
||||||
|
usename: nacos
|
||||||
|
passowrd: nacos
|
||||||
|
# gateway:
|
||||||
|
# discovery:
|
||||||
|
# locator:
|
||||||
|
# enabled: true # gateway 可以从 nacos 发现微服务
|
||||||
config:
|
config:
|
||||||
import:
|
import:
|
||||||
- nacos:qihang-oms.yaml?refresh=true
|
- nacos:qihang-oms.yaml?refresh=true
|
||||||
|
|
@ -16,6 +21,7 @@ spring:
|
||||||
server:
|
server:
|
||||||
port: 8082
|
port: 8082
|
||||||
|
|
||||||
|
|
||||||
#mybatis-plus:
|
#mybatis-plus:
|
||||||
# mapper-locations: classpath*:mapper/**/*Mapper.xml
|
# mapper-locations: classpath*:mapper/**/*Mapper.xml
|
||||||
# type-aliases-package: com.qihang.core.domain.entity;com.qihang.erp.api.domain
|
# type-aliases-package: com.qihang.core.domain.entity;com.qihang.erp.api.domain
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue