Spring boot 404 spring cloud gateway中针对每个备用请求的错误

Spring boot 404 spring cloud gateway中针对每个备用请求的错误,spring-boot,spring-cloud,api-gateway,spring-cloud-gateway,Spring Boot,Spring Cloud,Api Gateway,Spring Cloud Gateway,我在春云门遇到了一个非常奇怪的问题。每个备用请求返回一个404。这在我在api网关中配置的所有服务中都会发生,毫无例外。我甚至不知道从哪里开始调试这个问题 这是我的application.yml文件,用于公共配置 server: port: 8080 ssl: enabled: true key-store: classpath:keystore.p12 key-store-password: password key-store-type: pkcs12

我在春云门遇到了一个非常奇怪的问题。每个备用请求返回一个404。这在我在api网关中配置的所有服务中都会发生,毫无例外。我甚至不知道从哪里开始调试这个问题

这是我的application.yml文件,用于公共配置

server:
  port: 8080
  ssl:
    enabled: true
    key-store: classpath:keystore.p12
    key-store-password: password
    key-store-type: pkcs12
    key-alias: tomcat

security:
  require-ssl=true:
logging:
  level:
    org:
      springframework:
        cloud.gateway: DEBUG
        http.server.reactive: DEBUG
        web.reactive: DEBUG

spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      httpclient:
        ssl:
          useInsecureTrustManager: true
这是我的java配置文件


@EnableWebFluxSecurity
public class SecurityConfig {

    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http,
                                                            ReactiveClientRegistrationRepository clientRegistrationRepository) {
        // Authenticate through configured OpenID Provider
        http.oauth2Login();
        // Also logout at the OpenID Connect provider
        http.logout(logout -> logout.logoutSuccessHandler(new OidcClientInitiatedServerLogoutSuccessHandler(
                clientRegistrationRepository)));
        // Require authentication for all requests
        http.authorizeExchange().anyExchange().authenticated();
        // Allow showing /home within a frame
        http.headers().frameOptions().mode(Mode.SAMEORIGIN);
        // Disable CSRF in the gateway to prevent conflicts with proxied service CSRF
        http.csrf().disable();
        return http.build();
    }
}
下面是加载到common application.yml文件之上的特定于spring概要文件的配置文件

spring:
  security:
    oauth2:
      client:
        provider:
          keycloak:
            issuerUri: http://localhost:9080/auth/realms/mylocal
            userNameAttribute: preferred_username
        registration:
          keycloak:
            clientId: api-gateway-client
            clientSecret: abcdefgh-ijkl-mnop-qrst-uvwxyz5d6a9
  cloud:
    gateway:
      default-filters:
        - TokenRelay
      routes:
        - id: news
          uri: http://localhost:8082/news
          predicates:
            - Path= /news/**
        - id: customers
          uri: http://localhost:8083/customers
          predicates:
            - Path= /boards/**
        - id: search
          uri: http://localhost:8085/search
          predicates:
            - Path= /search/**

嘿,我最近也遇到了这个问题,我发现这是负载平衡的问题。确保您尝试联系的微服务的spring.application.name都是大写字母(示例),尤其是使用Eureka时。(希望有帮助)

我知道这是个老问题。。。但可能对未来的读者有所帮助

嘿,这是我为自己找到的最简单的解决方案,在浏览器中 url,而不是“localhost”,给出您的系统名称

例: http://hp:8083/SERVICE-姓名/客户/**

还要确保所有spring应用程序都用大写字母命名


谢谢负载平衡器是一个很好的探索途径。您能在这里输入您的示例配置吗?我尝试了大写字母的建议,但它不起作用。您使用的是配置服务器吗?如果是,只需在bootstrap.properties或.yml中添加以下内容:spring.application.name=MICROSERVICENAME全部大写例如:spring.application.name=OAUTH-SERVER,并确保您尝试使用注释@RibbonClient(name=“OAUTH-SERVER”)通过负载平衡器访问实例如果您使用ribbon:)并遵循相同的示例有趣的一个,您是否有任何文档或技术参考,这些名称必须以大写字母表示?我已经使用undercase多年了,这从来都不是问题。@PRF我没有看到通知,我现在将尝试查找它,就像刚才一样:)编辑:“eureka返回的值是大写的…”来源:spring cloud gateway遇到了同样的问题,你能解决吗?