带有Spring Boot和Hikari DataSource的JavaMelody

时间:2017-07-07 15:08:21

标签: java spring-boot java-melody

我在springboot projet中安装了javamelody(根据本教程:https://github.com/javamelody/javamelody/wiki/SpringBootStarter:没有spring-boot-starter安装)但是在runnig服务器上安装。

在application.yml文件中,我添加了  AOP:         proxy-target-class:true 但仍然没有工作。

请帮助。 我收到了这个错误:

"2017-07-07 14:55:20.582 WARN 10056 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.ryantenney.metrics.spring.config.annotation.DelegatingMetricsConfiguration': Unsatisfied dependency expressed through method 'setMetricsConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'metricsConfiguration': Unsatisfied dependency expressed through field 'hikariDataSource'; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'dataSource' is expected to be of type 'com.zaxxer.hikari.HikariDataSource' but was actually of type 'com.sun.proxy.$Proxy132'
2017-07-07 14:55:20.585 ERROR 10056 --- [ restartedMain] o.s.b.f.s.DefaultListableBeanFactory : Destroy method on bean with name 'dataSourceInitializer' threw an exception

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7d8e76e9: startup date [Fri Jul 07 14:55:14 CEST 2017]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:404)
at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:954)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:961)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:555)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at net.viamedis.kalivia.osteo.KaliviaOsteoApp.main(KaliviaOsteoApp.java:77)
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.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

APPLICATION FAILED TO START

Description:

The bean 'dataSource' could not be injected as a 'com.zaxxer.hikari.HikariDataSource' because it is a JDK dynamic proxy that implements:
javax.sql.DataSource
java.io.Closeable

Action:

Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @enableasync and/or @enablecaching."

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。对我有用的是手动定义HikariDataSource bean,因此需要设置proxy-target-class=true

@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public HikariDataSource dataSource() {
    return (HikariDataSource) DataSourceBuilder.create().type(HikariDataSource.class).build();
}

然后在application.yml中将属性url更改为jdbc-url。 我还为javaMelody添加了以下配置:

javamelody:
  enabled: true
  spring-monitoring-enabled: true
  init-parameters:
    log: true
    authorized-users: admin:********

现在,javaMelody正在运行,Spring Boot应用程序正常启动。 依赖性为"net.bull.javamelody:javamelody-spring-boot-starter:1.68.1"

提示:如果在添加javaMelody后您的单元测试被破坏,只需通过应用程序配置文件完全禁用它进行单元测试。

相关问题