Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micrometer dependencies throwing an exception when running in a native app using Hikari/Hibernate #4155

Closed
4 tasks done
ivangfr opened this issue Sep 23, 2020 · 5 comments · Fixed by micronaut-projects/micronaut-micrometer#158
Labels
relates-to: graal status: pr submitted A pull request has been submitted for the issue
Milestone

Comments

@ivangfr
Copy link

ivangfr commented Sep 23, 2020

Hi, I am getting an exception when running my native application with metrics.

The application is this one: https://github.com/ivangfr/graalvm-quarkus-micronaut-springboot/tree/master/book-api/micronaut-book-api

If those two lines in build.gradle are commented, everything works fine

...
    // implementation("io.micronaut.micrometer:micronaut-micrometer-core")
    // implementation("io.micronaut.micrometer:micronaut-micrometer-registry-prometheus")
...

However, when I uncomment it, build the native docker image of the app and run it, I am getting the following exception during the startup

[main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Bean definition [org.hibernate.SessionFactory] could not be   loaded: Error instantiating bean of type  [org.hibernate.boot.registry.StandardServiceRegistry]

Message: Class must be instance of com.codahale.metrics.MetricRegistry or io.micrometer.core.instrument.MeterRegistry
Path Taken: SessionFactory.hibernateSessionFactory([SessionFactoryBuilder sessionFactoryBuilder]) --> SessionFactoryBuilder.  hibernateSessionFactoryBuilder([MetadataSources metadataSources],ValidatorFactory validatorFactory) --> MetadataSources.  hibernateMetadataSources(JpaConfiguration jpaConfiguration,[StandardServiceRegistry standardServiceRegistry]) --> StandardServiceRegistry.  hibernateStandardServiceRegistry(String dataSourceName,[DataSource dataSource])
io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [org.hibernate.SessionFactory] could not be loaded: Error   instantiating bean of type  [org.hibernate.boot.registry.StandardServiceRegistry]

Message: Class must be instance of com.codahale.metrics.MetricRegistry or io.micrometer.core.instrument.MeterRegistry
Path Taken: SessionFactory.hibernateSessionFactory([SessionFactoryBuilder sessionFactoryBuilder]) --> SessionFactoryBuilder.  hibernateSessionFactoryBuilder([MetadataSources metadataSources],ValidatorFactory validatorFactory) --> MetadataSources.  hibernateMetadataSources(JpaConfiguration jpaConfiguration,[StandardServiceRegistry standardServiceRegistry]) --> StandardServiceRegistry.  hibernateStandardServiceRegistry(String dataSourceName,[DataSource dataSource])
	at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1540)
	at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:220)
	at io.micronaut.context.DefaultBeanContext.readAllBeanDefinitionClasses(DefaultBeanContext.java:2771)
	at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:228)
	at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:166)
	at io.micronaut.runtime.Micronaut.start(Micronaut.java:64)
	at io.micronaut.runtime.Micronaut.run(Micronaut.java:294)
	at io.micronaut.runtime.Micronaut.run(Micronaut.java:280)
	at com.mycompany.micronautbookapi.Application.main(Application.java:18)
Caused by: io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type  [org.hibernate.boot.registry.  StandardServiceRegistry]

Message: Class must be instance of com.codahale.metrics.MetricRegistry or io.micrometer.core.instrument.MeterRegistry
Path Taken: SessionFactory.hibernateSessionFactory([SessionFactoryBuilder sessionFactoryBuilder]) --> SessionFactoryBuilder.  hibernateSessionFactoryBuilder([MetadataSources metadataSources],ValidatorFactory validatorFactory) --> MetadataSources.  hibernateMetadataSources(JpaConfiguration jpaConfiguration,[StandardServiceRegistry standardServiceRegistry]) --> StandardServiceRegistry.  hibernateStandardServiceRegistry(String dataSourceName,[DataSource dataSource])
	at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1916)
	at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2638)
	at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2624)
	at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2296)
	at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2270)
	at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1240)
	at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:1013)
	at io.micronaut.data.hibernate.runtime.$DataEntityManagerFactoryBean$HibernateStandardServiceRegistry0Definition.doBuild(Unknown Source)
	at io.micronaut.context.AbstractParametrizedBeanDefinition.build(AbstractParametrizedBeanDefinition.java:118)
	at io.micronaut.context.BeanDefinitionDelegate.build(BeanDefinitionDelegate.java:139)
	at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1889)
	at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2638)
	at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2624)
	at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2296)
	at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2270)
	at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1240)
	at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:1013)
	at io.micronaut.configuration.hibernate.jpa.$EntityManagerFactoryBean$HibernateMetadataSources1Definition.doBuild(Unknown Source)
	at io.micronaut.context.AbstractParametrizedBeanDefinition.build(AbstractParametrizedBeanDefinition.java:118)
	at io.micronaut.context.BeanDefinitionDelegate.build(BeanDefinitionDelegate.java:139)
	at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1889)
	at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2638)
	at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2624)
	at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2296)
	at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2270)
	at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1240)
	at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:1013)
	at io.micronaut.configuration.hibernate.jpa.$EntityManagerFactoryBean$HibernateSessionFactoryBuilder2Definition.build(Unknown Source)
	at io.micronaut.context.BeanDefinitionDelegate.build(BeanDefinitionDelegate.java:143)
	at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1889)
	at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2638)
	at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2624)
	at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2296)
	at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2270)
	at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1240)
	at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:1013)
	at io.micronaut.configuration.hibernate.jpa.$EntityManagerFactoryBean$HibernateSessionFactory3Definition.build(Unknown Source)
	at io.micronaut.context.BeanDefinitionDelegate.build(BeanDefinitionDelegate.java:143)
	at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1889)
	at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2638)
	at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2624)
	at io.micronaut.context.DefaultBeanContext.loadContextScopeBean(DefaultBeanContext.java:2163)
	at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1538)
	... 8 common frames omitted
Caused by: java.lang.IllegalArgumentException: Class must be instance of com.codahale.metrics.MetricRegistry or io.micrometer.core.instrument.  MeterRegistry
	at com.zaxxer.hikari.HikariConfig.setMetricRegistry(HikariConfig.java:667)
	at com.zaxxer.hikari.HikariDataSource.setMetricRegistry(HikariDataSource.java:237)
	at io.micronaut.configuration.jdbc.hikari.DatasourceFactory.addMeterRegistry(DatasourceFactory.java:79)
	at io.micronaut.configuration.jdbc.hikari.DatasourceFactory.dataSource(DatasourceFactory.java:67)
	at io.micronaut.configuration.jdbc.hikari.$DatasourceFactory$DataSource0Definition.build(Unknown Source)
	at io.micronaut.context.BeanDefinitionDelegate.build(BeanDefinitionDelegate.java:143)
	at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1889)
	... 50 common frames omitted

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Clone project mentioned above
  2. Uncomment the 2 lines mentioned above
  3. Run the app by following the README

Expected Behaviour

No exception should be thrown

Actual Behaviour

It's throwing an exception as described above

Environment Information

  • Operating System: Mac
  • Micronaut Version: 2.0.3
  • JDK Version: 11

Example Application

https://github.com/ivangfr/graalvm-quarkus-micronaut-springboot/tree/master/book-api/micronaut-book-api

@agilob
Copy link

agilob commented Oct 3, 2020

I was working on adding native-image support to jhipster-micronaut and had the same issue. Compilation fails when micrometer is enabled, but another problem you might face later is, some hikari jdbc drivers dont compile correctly with native-image.

Eg. hikari with postgres compiles, but doesn't run when invoked

Caused by: io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type [javax.sql.DataSource]: Failed to initialize pool: The connection attempt failed.
        at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1918)
        at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2635)
        at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2621)
        at io.micronaut.context.DefaultBeanContext.loadContextScopeBean(DefaultBeanContext.java:2163)
        at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1538)
        ... 6 common frames omitted
Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: The connection attempt failed.
        at com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:595)
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:581)
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
        at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
        at io.micronaut.configuration.jdbc.hikari.HikariUrlDataSource.<init>(HikariUrlDataSource.java:35)
        at io.micronaut.configuration.jdbc.hikari.DatasourceFactory.dataSource(DatasourceFactory.java:66)
        at io.micronaut.configuration.jdbc.hikari.$DatasourceFactory$DataSource0Definition.build(Unknown Source)
        at io.micronaut.context.BeanDefinitionDelegate.build(BeanDefinitionDelegate.java:143)
        at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1889)
        ... 10 common frames omitted
Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:297)
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
        at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:217)
        at org.postgresql.Driver.makeConnection(Driver.java:458)
        at org.postgresql.Driver.connect(Driver.java:260)
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358)
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206)
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477)
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:560)
        ... 17 common frames omitted
Caused by: java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(SocketInputStream.java:186)
        at java.net.SocketInputStream.read(SocketInputStream.java:140)
        at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:161)
        at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:128)
        at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:113)
        at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:73)
        at org.postgresql.core.PGStream.receiveChar(PGStream.java:370)
        at org.postgresql.core.v3.ConnectionFactoryImpl.enableSSL(ConnectionFactoryImpl.java:416)
        at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:140)
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:197)
        ... 26 common frames omitted

Can you confirm you had this or similar issue with hikari and micronaut?

@graemerocher graemerocher added this to the 2.1.1 milestone Oct 3, 2020
@ivangfr
Copy link
Author

ivangfr commented Oct 3, 2020

Hi @agilob In my app, I am using MySQL and JPA/Hibernate/Hikari and I don't have any problem running it in JVM or Native mode. So, except for the metrics problem that I described in this issue, I don't have any database problem.

@graemerocher
Copy link
Contributor

PR submitted to the module micronaut-projects/micronaut-micrometer#158

@graemerocher graemerocher added the status: pr submitted A pull request has been submitted for the issue label Oct 7, 2020
@ivangfr
Copy link
Author

ivangfr commented Oct 14, 2020

Hi @graemerocher @ilopmar !

With the new version 2.1.1, I checked again the issue described above, and it seems that it's still present.

I am using the same app, micronaut-book-api (https://github.com/ivangfr/graalvm-quarkus-micronaut-springboot/tree/master/book-api/micronaut-book-api).

The changes I did, in build.gradle

  • 1st change
    from

    ext {
        set('micronautVersion', '2.0.3')
    ...
    }
    

    to

    ext {
        set('micronautVersion', '2.1.1')
    ...
    }
    
  • 2nd change
    from

    ...
        // implementation("io.micronaut.micrometer:micronaut-micrometer-core")
        // implementation("io.micronaut.micrometer:micronaut-micrometer-registry-prometheus")
    ...
    

    to

    ...
        implementation("io.micronaut.micrometer:micronaut-micrometer-core")
        implementation("io.micronaut.micrometer:micronaut-micrometer-registry-prometheus")
    ...
    

Am I missing something? Thanks!

@ivangfr
Copy link
Author

ivangfr commented Nov 21, 2020

Hi, it's just to let you know that the problem described above seems to be fixed when I updated my application to Micronaut version 2.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relates-to: graal status: pr submitted A pull request has been submitted for the issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants