Igor Konoplyanko
Igor Konoplyanko

Reputation: 9374

Spring actuator: /configprops not showing HikariCP datasource

I've switched recently to HikariCP instead of tomcat connection pool. I was checking connection properties via /configprops actuator endpoint, but now what I'm getting is this:

"dataSource" : {
 "prefix" : "spring.datasource.hikari",
 "properties" : {
  "error" : "Cannot serialize 'spring.datasource.hikari'"
 }
}

How can I make it return normal values? I've thought spring boot should handle this with org.springframework.boot.autoconfigure.jdbc.metadata.HikariDataSourcePoolMetadata

Upvotes: 1

Views: 1203

Answers (1)

Igor Konoplyanko
Igor Konoplyanko

Reputation: 9374

So what I've found that Hikari's DriverDataSource threw SQLFeatureNotSupportedException on some getters. Only way to overcome this problem is to customize actuator page. Luckily it happens to be relatively easy:

@Component
public class MyConfigurationPropertiesReportEndpoint extends ConfigurationPropertiesReportEndpoint {

  @Override
  protected void configureObjectMapper(ObjectMapper mapper) {
    super.configureObjectMapper(mapper);
    mapper.addMixIn(HikariDataSource.class, HikariDataSourceMixIn.class);
  }
}

And MixIn:

public abstract class HikariDataSourceMixIn {

  @JsonIgnore
  abstract PrintWriter getLogWriter();

  @JsonIgnore
  abstract HikariConfigMXBean getHikariConfigMXBean();
}

Upvotes: 1

Related Questions