作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试向 /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/
我正在尝试向 /info 端点发送更多信息: @Component public class InfoEndpoint implements InfoContributor { @Overri
我是一名优秀的程序员,十分优秀!