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

spring boot+hikari data source proxy issue #801

Closed
MeiyappanKannappa opened this issue Dec 18, 2018 · 3 comments
Closed

spring boot+hikari data source proxy issue #801

MeiyappanKannappa opened this issue Dec 18, 2018 · 3 comments

Comments

@MeiyappanKannappa
Copy link

I am trying to use Javamelody (version 1.75.0) in my Spring boot application (Spring Boot version 2.0.6) which is using Hikari datasource

# HIKARI SETTINGS #
spring.datasource.type=com.zaxxer.hikari.HikariDataSource

and below is the melody configuration

javamelody.enabled=true
javamelody.spring-monitoring-enabled=true
javamelody.init-parameters.log=true
javamelody.init-parameters.storage-directory=/tmp/javamelody
javamelody.advisor-auto-proxy-creator-enabled= false
javamelody.scheduled-monitoring-enabled= false
spring.jmx.enabled=false

But this doesnt work it gives me below exception, I need to monitor DB activities in melody. But spring boot app startup is throwing this error.

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.JpaVendorAdapter]: Factory method 'jpaVendorAdapter' threw exception; nested exception is java.lang.ClassCastException: com.sun.proxy.$Proxy134 cannot be cast to com.zaxxer.hikari.HikariDataSource
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:583)
	... 46 common frames omitted
Caused by: java.lang.ClassCastException: com.sun.proxy.$Proxy134 cannot be cast to com.zaxxer.hikari.HikariDataSource
	at com.zaxxer.hikari.HikariDataSource$$FastClassBySpringCGLIB$$eeb1ae86.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
	at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
	at com.zaxxer.hikari.HikariDataSource$$EnhancerBySpringCGLIB$$e55b5d8b.getConnection(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.bull.javamelody.JdbcWrapper$3.invoke(JdbcWrapper.java:781)
	at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:294)
	at com.sun.proxy.$Proxy127.getConnection(Unknown Source)
	at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:151)
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115)
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78)
	at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:319)
	at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:356)
	at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:72)
	at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:166)
	at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:111)
	at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$6fb38859.CGLIB$jpaVendorAdapter$3(<generated>)
	at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$6fb38859$$FastClassBySpringCGLIB$$25be11d4.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365)
	at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$6fb38859.jpaVendorAdapter(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 47 common frames omitted

Process finished with exit code 1

Can anyone help on this. Thank you!

@evernat
Copy link
Member

evernat commented Dec 20, 2018

This issue is the same as #742 (comment) except that you have spring.jmx.enabled=false.
One workaround is to enable Tomcat jdbc pool, like it was in Spring boot 1:

spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource

and

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
    <exclusions>
        <exclusion>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-jdbc</artifactId>
</dependency>

Closing as duplicate.

@evernat evernat closed this as completed Dec 20, 2018
@MeiyappanKannappa
Copy link
Author

So it means HikariCP cannot be used if we need to monitor with Melody?

@evernat
Copy link
Member

evernat commented Dec 20, 2018

It depends. Sometimes yes, sometimes no. In your case, you can't use HikariCP because of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants