我使用Spring云配置Finchley.M8版本与Spring boot 2.0.0.RELEASE。 我注意到/ 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 spring with spring 1.5.6并且工作正常,当我使用最新的Spring云版本迁移到Spring boot 2时遇到了这个问题。
答案 0 :(得分:0)
我找到了问题的解决方案,它是关于安全性的。 简单地说,我在WebSecurityConfigurerAdapter中修改了配置方法,还有两行。它将类似于以下代码段:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll();
http.csrf().disable();
http.httpBasic().disable();
}
答案 1 :(得分:0)
尝试此操作来解决您的问题:
spring-boot 2.0.1.RELEASE
spring-cloud-bus 2.0.0.RC1
management:
endpoints:
web:
exposure:
include: bus-refresh,refresh
base-path: /