Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

363
Views
How to use JMX MBean for HikariCP in Spring boot application?

How to use JMX MBean for HikariCP in Spring boot application? I have a code like this:

@SpringBootApplication
public class App() { ... }

And other class:

@Configuration
public class DatabaseCfg() {
@Bean
@ManagedOperation
public DataSource ds (@Value("${hikari.proprerties}") String config) {
HikariConfig hikariConfig = new HikariConfig(config);
return new HikariDataSource(hikariConfig);
}

In Java Mission Control (or JMX Console) a saw only Datasource managed bean, not JMX MBean for HikariCP (link). Is it possible to add it too?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

In Spring Boot 2.0+ you can set the register-mbeans property in your application.properties file

spring.datasource.hikari.register-mbeans = true

If you are using an earlier version of Spring Boot you will also have to set the datasource

spring.datasource.type = com.zaxxer.hikari.HikariDataSource 
over 4 years ago · Santiago Trujillo Report

0

I believe on your hikariConfig you need to set a few additional settings. You need to register the MBeans and set a pool name on the configuration.

HikariConfig hiakriConfig = new HikariConfig(config);
hikariConfig.setRegisterMbeans(true);
kikariConfig.setPoolName("my-pool-1");

Yes you obviously could drive these through the properties as well. I'm not sure if you are including these in your properties file as they are not listed. Also please note you are spelling properties wrong (@Value("${ds.proprerties}") should probably should be (@Value("${ds.properties}") but I'm not sure how you actually have named variables and property files. You may want to double check if that is where you want to set all of the properties.

over 4 years ago · Santiago Trujillo Report

0

Try this. Exclude your Hiakri DataSource Bean from being registered by Spring.

@Resource
private ObjectProvider<MBeanExporter> mBeanExporter;

@Bean("dataSource")
public DataSource createDataSource() {
    String url = hikariDataSourceConfig.getUrl();
    String username = hikariDataSourceConfig.getUsername();
    String password = hikariDataSourceConfig.getPassword();
    long idleTimeoutInMilliSeconds =
            hikariDataSourceConfig.getIdleTimeOutInMilliseconds();
    long maxLifetimeInMilliseconds =
            hikariDataSourceConfig.getMaxLifetimeInMilliseconds();
    int maximumPoolSize = hikariDataSourceConfig.getMaximumPoolSize();
    int minimumIdle = hikariDataSourceConfig.getMinimumIdle();
    String poolName = "HikariDataSource";
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setRegisterMbeans(true);
    hikariConfig.setJdbcUrl(url);
    hikariConfig.setUsername(username);
    hikariConfig.setPassword(password);
    hikariConfig.setIdleTimeout(idleTimeoutInMilliSeconds);
    hikariConfig.setMaxLifetime(maxLifetimeInMilliseconds);
    hikariConfig.setMaximumPoolSize(maximumPoolSize);
    hikariConfig.setMinimumIdle(minimumIdle);
    hikariConfig.setPoolName(poolName);
    HikariDataSource dataSource = new HikariDataSource(hikariConfig);
    mBeanExporter
            .ifUnique((exporter) -> exporter.addExcludedBean("dataSource"));
    return dataSource;
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!