Tag Archives: gateway

Springcloud builds a gateway and starts Error [Solved]

1.Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.

Solution:

           <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </exclusion>

2. Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

Solution:

             <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-jdbc</artifactId>
                </exclusion>

gateway Internal Server Error 500 Invalid host: lb://xxxxxx

The following error occurred while accessing other project interfaces through the gateway

2021-11-01 17:01:28.244 ERROR 4732 --- [ctor-http-nio-2] a.w.r.e.AbstractErrorWebExceptionHandler : [5761064e-3]  500 Server Error for HTTP GET "/admin/user/list"

java.lang.IllegalStateException: Invalid host: lb://zkdn_admin
	at org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter.filter(RouteToRequestUrlFilter.java:86) ~[spring-cloud-gateway-server-2.2.6.RELEASE.jar:2.2.6.RELEASE]
	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
	|_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
	|_ checkpoint ⇢ HTTP GET "/admin/user/list" [ExceptionHandlingWebHandler]
Stack trace:
		at org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter.filter(RouteToRequestUrlFilter.java:86) ~[spring-cloud-gateway-server-2.2.6.RELEASE.jar:2.2.6.RELEASE]

The reason is that the service name registered in Nacos has “”, which can be solved by changing the underscore to “-“.

Solution to the problem of using Alibaba gateway but unable to route successfully

One of the important functions of gateway is routing and forwarding. We often encounter the problem of forwarding failure
for example, the front-end configuration is as follows:

 // api interface request address
 window.SITE_CONFIG['baseUrl'] = 'http://localhost:90/api';

The application.yml configuration of gateway is as follows:

server:
  port: 90
spring:
  application:
    name: threat-gateway
  cloud:
    gateway:
      routes:
#        threat-ip microservice routing and forwarding
        - id: ip_route
# The forwarding address of the matching route
          uri: lb://threat-ip
          predicates:
            - Path=/api/cyber_threat_ip/**
          filters:
            - RewritePath=/api/(?<segment>.*),/$\{segment}

The reason for the error may be that the registry (such as Nacos) is not enabled, resulting in the unrecognized name of the microservice
it is revised as follows:

#          Match the forwarding address of the route (8082 is the threat-ip microservice port)
          uri: localhost:8082

As a result, an error was reported because http://, should be added in front of the URI, as follows:

#          Match the forwarding address of the route (8082 is the threat-ip microservice port)
          uri: http://localhost:8082

As a result, you can visit it

of course, the rewritepath path rewriting error in filters may also cause access error. Other reasons will be added later.