I'm trying to setup a Spring project and want to use Spring Boot Actuator 2.1.6. I've found list to pure POJO configurations but my app is using a XML config and wanted to keep using XML.
I've tried using the configuration listed below but it doesn't work as it's based on an earlier version of Actuator than I'm using.
<bean name="endpointHandlerAdapter" class="org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerAdapter" />
<bean name="endpointHandlerMapping" class="org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping" />
<bean class="org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration$InfoPropertiesConfiguration" />
<bean name="beansEndpoint" class="org.springframework.boot.actuate.endpoint.BeansEndpoint" />
<beans>
<context:annotation-config />
<bean name="endpointAutoConfiguration" class="org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration"/>
</beans>
Using the config I get a number of class not found errors as the mvc package doesn't appear to exist in the newer version of Spring boot.
EDIT: Reading a bit more it seems that all of the available configurations are for the older Spring Boot Actuator 1 not the newer stuff. It looks like the amount of config that is needed has multiplied. Still interested in the answer but not holding out hope.
This is what we did for our spring + jersey project. As we are using an older version of spring (4.x), used spring boot actuator v1.5.22.RELEASE. Excluded autoconfigure dependency.
pom.xml snippet:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>1.5.22.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</exclusion>
</exclusions>
</dependency>
XML config snippet:
<!-- Health -->
<bean id="orderedHealthAggregator" class="org.springframework.boot.actuate.health.OrderedHealthAggregator" />
<bean id="applicationHealthIndicator" class="org.springframework.boot.actuate.health.ApplicationHealthIndicator" />
<bean id="dataSourceHealthIndicator" class="org.springframework.boot.actuate.health.DataSourceHealthIndicator">
<constructor-arg index="0" ref="optimaxDataSource" />
</bean>
<bean id="jmsHealthIndicator" class="org.springframework.boot.actuate.health.JmsHealthIndicator">
<constructor-arg index="0" ref="connectionFactory" />
</bean>
<bean id="mailHealthIndicator" class="org.springframework.boot.actuate.health.MailHealthIndicator">
<constructor-arg index="0" ref="mailSender" />
</bean>
<!-- TODO: Set threshold value for disk space -->
<bean id="diskSpaceHealthIndicatorProperties" class="org.springframework.boot.actuate.health.DiskSpaceHealthIndicatorProperties" />
<bean id="diskSpaceHealthIndicator" class="org.springframework.boot.actuate.health.DiskSpaceHealthIndicator">
<constructor-arg index="0" ref="diskSpaceHealthIndicatorProperties" />
</bean>
<bean id="healthEndpoint" class="org.springframework.boot.actuate.endpoint.HealthEndpoint">
<constructor-arg index="0" ref="orderedHealthAggregator" />
<constructor-arg index="1" type="java.util.Map">
<map>
<entry key="application" value-ref="applicationHealthIndicator" />
<entry key="db" value-ref="dataSourceHealthIndicator" />
<entry key="jms" value-ref="jmsHealthIndicator" />
<entry key="mail" value-ref="mailHealthIndicator" />
<entry key="disk" value-ref="diskSpaceHealthIndicator" />
</map>
</constructor-arg>
</bean>
<!-- Git & Build Info -->
<bean id="gitClasspathProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="singleton" value="true" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:git.properties</value>
</list>
</property>
</bean>
<bean id="gitProperties" class="org.springframework.boot.info.GitProperties">
<constructor-arg index="0" ref="gitClasspathProperties" />
</bean>
<bean id="gitInfoContributor" class="org.springframework.boot.actuate.info.GitInfoContributor">
<constructor-arg index="0" ref="gitProperties" />
<constructor-arg index="1">
<value type="org.springframework.boot.actuate.info.InfoPropertiesInfoContributor.Mode">FULL</value>
</constructor-arg>
</bean>
<bean id="buildClasspathProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="singleton" value="true" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:build-info.properties</value>
</list>
</property>
</bean>
<bean id="buildProperties" class="org.springframework.boot.info.BuildProperties">
<constructor-arg index="0" ref="buildClasspathProperties" />
</bean>
<bean id="buildInfoContributor" class="org.springframework.boot.actuate.info.BuildInfoContributor">
<constructor-arg index="0" ref="buildProperties" />
</bean>
<bean id="infoEndpoint" class="org.springframework.boot.actuate.endpoint.InfoEndpoint">
<constructor-arg index="0" type="java.util.List">
<list>
<ref bean="gitInfoContributor" />
<ref bean="buildInfoContributor" />
</list>
</constructor-arg>
</bean>
<!-- Metrics -->
<bean id="systemPublicMetrics" class="org.springframework.boot.actuate.endpoint.SystemPublicMetrics" />
<bean id="metricsEndpoint" class="org.springframework.boot.actuate.endpoint.MetricsEndpoint">
<constructor-arg index="0" ref="systemPublicMetrics" />
</bean>
<!-- Beans -->
<bean id="beansEndpoint" class="org.springframework.boot.actuate.endpoint.BeansEndpoint" />
<!-- Env -->
<bean id="environmentEndpoint" class="org.springframework.boot.actuate.endpoint.EnvironmentEndpoint" />
<!-- Thread Dump -->
<bean id="threadDumpEndpoint" class="org.springframework.boot.actuate.endpoint.DumpEndpoint" />
Exposed the monitoring functionality via a Jersey resource.
@Path("/actuator")
public class ActuatorResource {
private static final ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
@Autowired
private HealthEndpoint healthEndpoint;
@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("/health")
@Transactional(readOnly = true)
public Response getHealth() throws JsonProcessingException {
return invoke(healthEndpoint);
}
private Response invoke(Endpoint<?> endpoint) {
try {
return Response.ok().entity(mapper.writeValueAsString(endpoint.invoke())).build();
} catch (Throwable t) {
logger.error("Error invoking endpoint : {}", endpoint.getClass().getName(), t);
return Response.serverError().entity("Request processing failed").build();
}
}
}
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With