发送请求'POST'Zuul和响应:请求方法'GET'不支持|弹簧靴

时间:2019-12-11 17:38:25

标签: java spring-boot spring-cloud

我正在使用Spring Cloud,我已经配置了Eureka和Zuul。在Spring引导中部署Api Rest并通过Zuul使用rest POST服务时,我收到一条HTTP 405错误消息。

我正在检查日志,并出现以下消息:

Request method 'GET' not supported
2019-12-11 12: 19: 04.679 WARN 5724 --- [nio-8089-exec-6] .m.m.a.ExceptionHandlerExceptionResolver: Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported]

奇怪的是,当我直接使用该服务时,它可以正常工作,但是由于Zuul,看来我是通过GET发送的,但实际上我总是通过POST发送的。

Api Rest具有通过JWT配置的安全性,我不知道是否需要做任何额外的配置

非常感谢,如果有人可以帮助我,我将不胜感激。

application.yml

spring:
  application:
    name: kentaurus-zuul-server

server:
  port: 8082
  servlet:
    contextPath: /api/v1

#Endpoints
#endpoints:
 # restart:
  #  enabled: true
  #shutdown:
  #  enabled: true
  #health:
   # sensitive: false

#Zuul routes active
zuul:
  routes:
    kentaurus-page-core:
      service-id: kentaurus-page-core
      path: /public/kentaurus-page/**
      sensitiveHeaders: Cookie,Set-Cookie
      url: http://localhost:8089
      # stripPrefix : true

management:
  endpoints:
    kentaurus-page-core:
      exposure:
        include: "*"
        exclude:

#Eureka Instance ID
eureka:
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8081/eureka/
  instance:
    hostname: localhost
    instanceId: ${spring.application.name}:${server.port}

#Ribbon Activation
ribbon:
  eureka:
    enabled: true

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.kentaurus.zuul.server</groupId>
    <artifactId>kentaurus-zuul-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>kentaurus-zuul-server</name>
    <description>Eureka Service</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>

        <!-- Dependency to use a spring cloud config server -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <!-- Dependency to register the service within Eureka -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>

        <!-- Dependency to use a spring cloud config server -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <!-- Dependency to register the service within Eureka -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
    </dependencies>

    <!-- Dependency Management -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>



0 个答案:

没有答案