gpt4 book ai didi

java - 我的 InfoContributor 未向 Actuator 端点发送信息

转载 作者:行者123 更新时间:2023-12-02 11:02:09 25 4
gpt4 key购买 nike

我正在尝试向 /info 端点发送更多信息:

@Component
public class InfoEndpoint implements InfoContributor {

@Override
public void contribute(Info.Builder builder) {
Map<String, Integer> userDetails = new HashMap<>();
userDetails.put("teste", 23);
userDetails.put("teste2", 22);

builder.withDetail( "menuitems", userDetails );
}


}

但是访问http://myapp/actuator/info后我看不到该信息。为了进行一些测试,我在 application.properties 中放入了一些信息数据,例如 info.app.name,然后我只能看到这个。

我做错了什么?

编辑:Here you can find my real project (抱歉:pt_BR 中的备注)。编辑:我的整个 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>br.com.cmabreu</groupId>
<artifactId>hydra</artifactId>
<version>1.0</version>
<packaging>war</packaging>

<name>hydra</name>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<relativePath/>
</parent>

<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.BUILD-SNAPSHOT</spring-cloud.version>
<maven.test.skip>true</maven.test.skip>
</properties>

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

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>


<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<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-actuator</artifactId>
</dependency>


<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</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>

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>

最佳答案

在日志中我发现以下消息:

o.s.b.f.s.DefaultListableBeanFactory: Overriding bean definition for bean 'infoEndpoint' with a different definition: replacing [Generic bean: class [br.com.cmabreu.InfoEndpoint]; defined in file [C:\...\hydra\target\classes\br\com\cmabreu\InfoEndpoint.class]] with [Root bean: class [null]; factoryBeanName=org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration; factoryMethodName=infoEndpoint; defined in class path resource [org/springframework/boot/actuate/autoconfigure/info/InfoEndpointAutoConfiguration.class]]

看起来您的自定义 bean 已替换为默认 bean,因为它们具有相同的名称。一种解决方案是更改类的名称,例如:

@Component
public class ExtendedInfoEndpoint implements InfoContributor {
Map<String, Integer> userDetails = new HashMap<>();
userDetails.put("teste", 23);
userDetails.put("teste2", 22);
builder.withDetail( "menuitems", userDetails );
}

另一个解决方案是使用属性的值:

@Component(value = "extendedInfoEndpoint")
public class InfoEndpoint implements InfoContributor {
Map<String, Integer> userDetails = new HashMap<>();
userDetails.put("teste", 23);
userDetails.put("teste2", 22);
builder.withDetail( "menuitems", userDetails );
}

关于java - 我的 InfoContributor 未向 Actuator 端点发送信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51252138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com