1

我使用带有 Spring boot 2.0.0.RELEASE 的 Spring cloud config Finchley.M8 版本。我注意到 /bus/refresh 已更改为 /bus-refresh。但是,每当我使用 post http 请求点击 url 时,它就无法正常工作。这是 application.properties 的片段:

spring.cloud.bus.enabled=true
management.endpoints.web.exposure.include=bus-refresh,refresh
management.endpoints.web.base-path=/

此外,我扩展了 WebSecurityConfigurerAdapter 以添加以下代码片段:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll();
}

这是我试图测试的网址:

post http://localhost:8000/bus-refresh?destination=**:dev

然后我收到以下错误消息

{
"timestamp": "2018-03-18T07:03:54.135+0000",
"status": 403,
"error": "Forbidden",
"message": "Forbidden",
"path": "/bus-refresh"
}

此外,这里是 pom.xml 中依赖项的片段:

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <spring-cloud.version>Finchley.M8</spring-cloud.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-monitor</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bus-amqp</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
    <dependency>
        <groupId>com.rabbitmq</groupId>
        <artifactId>amqp-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security.oauth.boot</groupId>
        <artifactId>spring-security-oauth2-autoconfigure</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.retry</groupId>
        <artifactId>spring-retry</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.integration</groupId>
        <artifactId>spring-integration-amqp</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-properties-migrator</artifactId>
    </dependency>
</dependencies>

请问有什么帮助吗?

注意:我使用的是带有 spring 1.5.6 的旧版本的 spring cloud,它工作正常,当我使用最新的 spring cloud 版本迁移到 Spring boot 2 时遇到了这个问题。

4

2 回答 2

0

我想出了解决我的问题的方法,它是关于安全性的。我只是在我的 WebSecurityConfigurerAdapter 中修改了 configure 方法,增加了两行。就像下面的代码片段:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll();
    http.csrf().disable();
    http.httpBasic().disable();
}
于 2018-03-18T10:02:13.583 回答
0

试试这个来解决你的问题:

spring-boot 2.0.1.RELEASE
spring-cloud-bus 2.0.0.RC1

management:
  endpoints:
    web:
      exposure:
        include: bus-refresh,refresh

      base-path: /
于 2018-04-27T10:16:31.170 回答