官术网_书友最值得收藏!

Exposing configuration details

Spring Boot Actuator provides some endpoints that expose the configuration details of your Spring application. These endpoints provide you all configured bean details and also provide insight into the decisions that auto-configuration made when populating the Spring application context. Let's see the most essential endpoint for exploring an application's Spring context, which is the /beans endpoint. This endpoint returns information in the form of JSON as follows:

[
{
context: "application",
parent: null,
beans:
[
{
bean: "springBootActuatorApplication",
scope: "singleton",
type: "com.dineshonjava.sba.SpringBootActuatorApplication$$EnhancerBySpringCGLIB$$ee8dc6d9",
resource: "null",
dependencies: [ ]
},
{
bean: "org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory",
scope: "singleton",
type: "org.springframework.core.type.classreading.CachingMetadataReaderFactory",
resource: "null",
dependencies: [ ]
},
{
bean: "loginService",
scope: "singleton",
type: "com.dineshonjava.sba.LoginService",
resource: "file [D:/packt-spring-boot-ws/SpringBootActuator/target/classes/com/dineshonjava/sba/LoginService.class]",
dependencies:
[
"counterService"
]
},
{
bean: "myCustomEndpoint",
scope: "singleton",
type: "com.dineshonjava.sba.MyCustomEndpoint",
resource: "file [D:/packt-spring-boot-ws/SpringBootActuator/target/classes/com/dineshonjava/sba/MyCustomEndpoint.class]",
dependencies: [ ]
},..... 

As you can see in the preceding JSON data of the /beans endpoint, all configured beans in the application have the following information about the bean:

  • Bean: A bean is a name or ID of the configured bean in your Spring application
  • Dependencies: The dependency is a list of bean IDs that this bean is injected with
  • Scope: It exposes the bean's scope
  • Type: The bean's Java type

The /beans shows all the beans configured in the application. Beans are super important for applications configured on Spring. It is an object that is initialized, assembled, and managed at Spring IoC container. The /autoconfig endpoint provides an auto-configuration report of all the auto-configurations applied in the application. Spring Boot auto-configuration is built upon Spring conditional configuration. Spring Boot provides multiple configuration classes with @Conditional annotations. This @Conditional annotation decides whether beans should be automatically configured. Let's see the following JSON data that the /autoconfig endpoint provides:

{
positiveMatches:
{
AuditAutoConfiguration#auditListener:
[
{
condition: "OnBeanCondition",
message: "@ConditionalOnMissingBean (types: org.springframework.boot.actuate.audit.listener.AbstractAuditListener; SearchStrategy: all) found no beans"
}
],
AuditAutoConfiguration#authenticationAuditListener:
[
{
condition: "OnClassCondition",
message: "@ConditionalOnClass classes found: org.springframework.security.authentication.event.AbstractAuthenticationEvent"
},
{
condition: "OnBeanCondition",
message: "@ConditionalOnMissingBean (types: org.springframework.boot.actuate.security.AbstractAuthenticationAuditListener; SearchStrategy: all) found no beans"
}
..........
],
negativeMatches:
{
CacheStatisticsAutoConfiguration:
[
{
condition: "OnBeanCondition",
message: "@ConditionalOnBean (types: org.springframework.cache.CacheManager; SearchStrategy: all) found no beans"
}
],
CacheStatisticsAutoConfiguration.CaffeineCacheStatisticsProviderConfiguration:
[
{
condition: "OnClassCondition",
message: "required @ConditionalOnClass classes not found: com.github.benmanes.caffeine.cache.Caffeine,org.springframework.cache.caffeine.CaffeineCacheManager"
},
{
condition: "ConditionEvaluationReport.AncestorsMatchedCondition",
message: "Ancestor 'org.springframework.boot.actuate.autoconfigure.CacheStatisticsAutoConfiguration' did not match"
}
],.....
} 

The preceding JSON is the output of the /autoconfig endpoint. This JSON is pided into two parts—positiveMatches and negativeMatches. Data under negativeMatches means there's a condition that decides whether to configure a bean. And positiveMatches means you'll find a condition used to decide whether Spring Boot should auto-configure a bean.

Let's look at another configuration endpoint, /env; it shows different properties of all configurable environments in Spring:

{
profiles: [ ],
server.ports: {
local.server.port: 8080
},
commandLineArgs: {
spring.output.ansi.enabled: "always"
},
servletContextInitParams: { },
systemProperties: {
.....
sun.boot.library.path: "C:Program FilesJavajre1.8.0_151bin",
java.vm.version: "25.151-b12",
java.vm.vendor: "Oracle Corporation",
java.vendor.url: "http://java.oracle.com/",
java.rmi.server.randomIDs: "true",
path.separator: ";",
java.vm.name: "Java HotSpot(TM) 64-Bit Server VM",
file.encoding.pkg: "sun.io",
user.name: "Dinesh.Rajput",
com.sun.management.jmxremote: "",
java.vm.specification.version: "1.8",
sun.java.command: "com.dineshonjava.sba.SpringBootActuatorApplication --spring.output.ansi.enabled=always",
java.home: "C:Program FilesJavajre1.8.0_151",
sun.arch.data.model: "64",
sun.desktop: "windows",
sun.cpu.isalist: "amd64"
},
systemEnvironment: {
.....
LOCALAPPDATA: "C:UsersDinesh.RajputAppDataLocal",
PROCESSOR_LEVEL: "6",
FP_NO_HOST_CHECK: "NO",
USERDOMAIN: "TIMESGROUP",
LOGONSERVER: "\TGNOIFCTYDC01",
JAVA_HOME: "C:Program FilesJavajdk1.8.0_121",
SESSIONNAME: "Console",
APPDATA: "C:UsersDinesh.RajputAppDataRoaming",
USERNAME: "Dinesh.Rajput",
ProgramFiles(x86): "C:Program Files (x86)",
VBOX_MSI_INSTALL_PATH: "C:Program FilesOracleVirtualBox",
CommonProgramFiles: "C:Program FilesCommon Files",
.....
},
applicationConfig: [classpath:/application.properties]: {
endpoints.health.enabled: "true",
endpoints.health.id: "health",
management.port: "8080",
info.app.description: "This is my first Working Spring Actuator Examples",
info.app.version: "0.0.1-SNAPSHOT",
endpoints.info.id: "info",
endpoints.metrics.id: "metrics",
endpoints.metrics.sensitive: "false",
endpoints.metrics.enabled: "true",
security.user.name: "admin",
management.security.enabled: "true",
security.user.password: "******",
management.context-path: "/",
info.app.name: "Spring Boot Actuator Application",
endpoints.health.sensitive: "false",
security.basic.enabled: "true",
endpoints.info.enabled: "true",
endpoints.info.sensitive: "false"
}
}

Now let's see how the endpoint exposes the metric of your application.

主站蜘蛛池模板: 年辖:市辖区| 竹山县| 湘西| 四川省| 德州市| 砀山县| 湄潭县| 河曲县| 喜德县| 海兴县| 台中县| 湘潭县| 图片| 抚顺县| 孟津县| 齐齐哈尔市| 合肥市| 黎平县| 南召县| 廉江市| 农安县| 永善县| 房产| 靖西县| 广饶县| 新龙县| 滕州市| 普定县| 内黄县| 大姚县| 建水县| 西城区| 科技| 喜德县| 柳林县| 台中市| 徐闻县| 华池县| 新疆| 灌云县| 宣城市|