# 项目代码资源:
可能还在审核中,请等待。。。
https://download.csdn.net/download/chenhz2284/89437506
# 项目代码
【pom.xml】
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.12.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.3.12.RELEASE</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<compilerArgs>
<!--
添加编译参数【-parameters】很重要,没有这个参数的话【/actuator/chzEndpoint/p1】这个地址无法访问
-->
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.12.RELEASE</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
【application.properties】
server.port=8080
spring.application.name=myActuator
management.server.port=8080
management.endpoints.web.exposure.include=*
# 这里是【/actuator/info】要输出的内容
info.application.name=I am myActuator
info.application.version=1.0.1
【InfoEndpointExtension.java】
package com.chz.myActuator.actuator;
@Component
@EndpointWebExtension(endpoint = InfoEndpoint.class)
public class InfoEndpointExtension {
@Autowired
private InfoEndpoint delegate;
@ReadOperation
public Map<String, Object> info()
{
Map<String, Object> info = new HashMap<>(delegate.info());
info.put("chz_new_p", "info: I am new p"); // 加个属性
return info;
}
@ReadOperation
public Map<String, Object> infoExt(@Selector String name)
{
Map<String, Object> info = new HashMap<>(delegate.info());
info.put(name, "infoExt: I am new p"); // 加个属性
return info;
}
}
【MyActuatorTest.java】
package com.chz.myActuator;
@SpringBootApplication
public class MyActuatorTest {
public static void main(String[] args) {
SpringApplication.run(MyActuatorTest.class, args);
}
}
# 运行与测试
运行【MyActuatorTest】
访问【http://localhost:8080/actuator/info】
访问【http://localhost:8080/actuator/info/ddd】