我是Spring Cloud的新手,所以我正在使用一个视频教程,因此要读取暴露的端点,我尝试打开http://localhost:8000/actuator/mappings,但对我而言不起作用,但是/ health网址给了我结果如下:
这是客户端的书面代码:
@RefreshScope
@RestController
class MessageRestController {
@Value("${message}")
private String message;
@RequestMapping("/message")
String getMessage() {
return this.message;
}
}
pom.xml:
<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.spring.cloud.reservation</groupId>
<artifactId>reservation-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>reservation-service</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<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>
这是客户项目结构:
bootstrap.properties:
spring.application.name=reservation-service
spring.cloud.config.uri=http://localhost:8888
在/ refresh上执行发布时,提示我:未发现错误
curl -d {} http://localhost:8000/actuator/refresh
spring-boot-actuator jar版本= 2.1.3
答案 0 :(得分:1)
从Spring boot 2.x开始,默认情况下,除少数非敏感端点(例如/ health和/ info)外,所有执行器端点均被禁用。
您可以使用属性management.endpoints.web.exposure.include=*
有关更多详细信息,请参阅here。
答案 1 :(得分:1)
const
title = ['title 1', 'title 2', 'title 3'],
description = ['description 1', 'description 2', 'description 3'],
link = ['link 1', 'link 2', 'link 3'],
result = [title, description, link].reduce((a, b) => a.map((v, i) => v + '|' + b[i]));
console.log(result);
由于默认提供了Default management.endpoints.web.exposure.include, info, health
和执行器/信息,您将获得信息
management.endpoints.web.exposure.include = * //将允许所有端点 暴露
actuator/health
保护端点
management.endpoints.web.exposure.include=health,info # Endpoint IDs that should be included or '*' for all.
management.endpoints.web.exposure.exclude= # Endpoint IDs that should be excluded or '*' for all.
management.endpoints.web.base-path=/actuator # Base path for Web endpoints. Relative to server.servlet.context-path or management.server.servlet.context-path if management.server.port is configured.
management.endpoints.web.path-mapping= # Mapping between endpoint IDs and the path that should expose them.
启用/禁用端点
management.endpoint.health.roles= # Roles used to determine whether or not a user is authorized to be shown details. When empty, all authenticated users are authorized. //for health
management.endpoint.health.show-details=always,never # When to show full health details.
答案 2 :(得分:1)
Spring boot 2.x ::默认情况下仅公开运行状况和信息,为了公开其他执行器端点,请提及端点名称或添加以下行以公开所有端点。
management.endpoints.web.exposure.include:“ *”