2017-07-07 195 views
1

我在springboot projet中安裝javamelody(根據本教程:https://github.com/javamelody/javamelody/wiki/SpringBootStarter:安裝時沒有使用spring-boot-starter),但在runnig服務器時。JavaMelody與Spring Boot和Hikari DataSource

在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[email protected]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." 
+0

這有什麼更新?我也有同樣的問題... – Tobias

回答

0

我有同樣的問題。什麼工作對我來說是手動定義HikariDataSource豆,所以你做需要設置proxy-target-class=true

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

然後在application.yml更改屬性urljdbc-url。 我還增加了javaMelody以下配置:

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

現在,javaMelody工作和Spring引導應用可以正常啓動。 依賴是"net.bull.javamelody:javamelody-spring-boot-starter:1.68.1"

提示:如果你的單元測試添加javaMelody破後,就完全禁用它通過應用程序配置文件的單元測試。