我从 spring 站点(https://spring.io/guides/gs/actuator-service)下载了这个示例,我遵循了相同的步骤,但是如果我调用这个 URL
显示http://localhost:9000/health spring启动错误页面
spring boot 版本是1.4.1,应该是 {"status":"UP"},有什么建议吗?
应用程序属性
server.port: 9000
management.port: 9001
management.address: 127.0.0.1
Run Code Online (Sandbox Code Playgroud)
POM文件
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-actuator-service</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</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-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
日志:
我创建了一个简单的示例项目,仅包含spring-web和spring-actuator。我无法/actuator在该项目中调用端点。我唯一得到的是404错误:
There was an unexpected error (type=Not Found, status=404).
No message available
在日志中,我什么都看不到。为了避免安全问题,我激活了management.security.enabled=false中的application.properties。
在其他具有相同spring,spring-web和spring-actuator版本的项目中,我达到了/actuator终点,但看不到差异。
这是示例项目的github链接:https : //github.com/ManuZiD/mzd-actuator
任何建议都很好。提前致谢。
在 spring文档中,我已经阅读了由执行器依赖项提供的名为“执行器”的端点,但我没有设法在我的本地测试应用程序上访问它。
问题:有人知道如何访问该端点吗?如果可能的话,粗略的:)
子问题 1:如果这个端点存在,那么为什么它是隐藏的?
子问题 2:如果此端点不存在,我们如何通知 spring.io 更正文档页面(打开某种票证)?
细节:
我第一次使用 Spring Boot 应用程序时,执行器没有受到保护,因此很容易通过 /actuator/shutdown 端点远程关闭。最近,我使用 Spring security 保护了我的执行器,并且它起作用了。现在我需要提供 http 基本凭据来访问端点,但现在对 /actuator/shutdown 端点的curl 调用失败并出现禁止错误。我一定是某个地方配置不正确。
我的卷曲命令:
curl -XPOST -u 执行器:密码http://主机:端口/执行器/shutdown -k
我可以调用其他端点,似乎只有关闭端点被禁止。
我的配置:
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.info.git.mode=full
management.endpoint.shutdown.enabled=true
management.server.port=8081
spring.security.user.name=actuator
spring.security.user.roles=ACTUATOR
spring.security.user.password=password
Run Code Online (Sandbox Code Playgroud)
编辑:
@Configuration
public static class ActuatorWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests()
.anyRequest().hasRole("ACTUATOR")
.and()
.httpBasic();
}
}
Run Code Online (Sandbox Code Playgroud) 配置: springCloudVersion = 'Finchley.SR1' springBootVersion = '2.0.2.RELEASE'
得到以下错误:
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.actuate.metrics.CounterService
Run Code Online (Sandbox Code Playgroud)
这个版本的 spring-starter-actuator-2.0.2.RELEASE 中没有 CounterService 类??参考:https : //docs.spring.io/spring-boot/docs/2.0.2.RELEASE/api/
在我发现 Spring Boot 的 Info Actuator 几乎拥有我想要发布的所有内容之前,我创建了一些元端点以确保我可以访问构建和 Git 信息,这些信息在尝试验证以下内容时会有所帮助:
这样做之后,我确实开始发现 Info 执行器,它为我回答了几乎所有这些问题,但是我想添加 Git 信息中的一些内容——主要是提交消息和肮脏的旗帜。
如果我打开完整的 git 元数据,我会查看输出:
management.info.git.mode=full
Run Code Online (Sandbox Code Playgroud)
但是......这增加了更多的信息,其中大部分我并不关心,所以它比我真正想要的要多。
我想做的是获取 GitInfoContributor 并扩展/替换它,但我不完全确定如何做到这一点。添加我自己的贡献者很容易,但是如果我添加我自己的贡献者并调用 builder.withDetails("git"),如下所示:
package ca.cpp.api.submitapi.config
import org.springframework.boot.actuate.info.Info
import org.springframework.boot.actuate.info.InfoContributor
import org.springframework.boot.info.GitProperties
import org.springframework.stereotype.Component
@Component
class CustomGitInfoContributor(private val properties: GitProperties): InfoContributor {
override fun contribute(builder: Info.Builder?) {
builder?.withDetail("git",mapOf("dirty" to properties.get("dirty"))
}
}
Run Code Online (Sandbox Code Playgroud)
这取代了整个 git 属性集,同时,我认为核心 GitInfoContributor 仍然存在,仍然提供我丢弃的信息。
有没有一种合理的方法来只添加我想要的元素,或者使用我自己的贡献者,可以将其信息与“git”下已有的信息合并,或者通过某种方式扩展/替换现有的 GitInfoContributor?
我们最近在其中一个应用程序中将Spring-Boot版本升级到2.1.2。当我访问以下URL时,我注意到JSON格式发生了变化: http:// localhost:xxxx / health。
更改后的结构为:{运行状况:{状态:“启动”}}
先前是:{状态:“启动”}
我的问题是;1.为什么要对其进行修改?2.是否有任何配置可以保持以前的结构?
我有简单的配置服务器实现,当我浏览/health端点时,我得到:
{
status:"UP",
"details":{
"configserver":{
"status":"UP",
"details":{
"repositories":[
{
...
Run Code Online (Sandbox Code Playgroud)
如何在我的配置服务器再次检查配置服务器运行状况的情况下停止此操作。这导致配置服务器多次调用 git,这在我的场景中是不需要的。
spring-boot spring-cloud spring-boot-actuator actuator configserver
最近我将 spring-boot-starter-actuator 更新到 2.2.2,当我使用端点时,/health我得到:
{
"groups": [],
"status": {
"code": "UP",
"description": ""
}
}
Run Code Online (Sandbox Code Playgroud)
代替:
{
"status": "UP"
}
Run Code Online (Sandbox Code Playgroud)
我不知道其中的原因。任何想法?或者如何将输出 json 重新格式化为原始格式?不覆盖 HealthIndicator,仅重新格式化。
提前致谢。
在我的服务 /actuator/health 端点之一中,需要更多时间(大约 9 秒)。我正在使用以下依赖项,如何调试?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
使用的 Spring Boot 版本: 2.0.3.RELEASE
谢谢,哈里
spring-boot ×9
spring ×4
actuator ×1
configserver ×1
curl ×1
endpoint ×1
java ×1
spring-cloud ×1
spring-mvc ×1