spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

JavaMelody problem

Open ageery opened this issue 12 years ago • 3 comments

I'm using JavaMelody [https://code.google.com/p/javamelody/] with SpringBoot, but I'm getting the following exception:

Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dataSource': Bean with name 'dataSource' has been injected into other beans [dataSourceInitializer] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.

I believe the problem is that JavaMelody wraps the DataSource object in a proxy via its SpringDataSourceBeanPostProcessor class so it can monitor it. However, the DataSource has already been injected, in a non-wrapped form, in the JpaBaseConfiguration object.

Is there an easy workaround for this or any things I should try or look at?

Thanks Andrew

ageery avatar Nov 21 '14 16:11 ageery

I'm not familiar with JavaMelody. One option might be to try an define your own DataSource bean rather than relying on the auto-configuraration.

If you can put together a sample application that shows the problem I can try to take a look.

philwebb avatar Nov 21 '14 20:11 philwebb

I was able to solve this problem by excluding the DataSource from auto-configuration. Try this: @EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class) on your configuration class.

davidkiss avatar Dec 04 '14 18:12 davidkiss

Thanks -- works for me! Just in case someone else runs across this: after you exclude the DataSourceAutoConfiguration.class, you have to supply your own DataSource (obviously).

@Bean public DataSource dataSource() { ... }

ageery avatar Dec 05 '14 02:12 ageery