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

NoSuchMethodException: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceWrapper.<init>() #1799

Closed
wenlincheng opened this issue Jan 1, 2021 · 8 comments
Labels
dependencies Pull requests that update a dependency file tracing

Comments

@wenlincheng
Copy link

wenlincheng commented Jan 1, 2021

Bug Report

When init data source, the DruidDataSourceWrapper can not find the Init function.
version:

  • elasticjob-lite-spring-boot-starter 3.0.0-RC1
  • springboot 2.3.2
  • druid-starter 1.1.20
2021-01-01 22:13:10.923 ERROR 26227 -- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.shardingsphere.elasticjob.lite.spring.boot.job.ElasticJobBootstrapConfiguration': Invocation of init method failed; nested exception is java.lang.NoSuchMethodException: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceWrapper.<init>()
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:415)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:241)
	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:723)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140)
	at com.wenlincheng.pika.schedule.PikaScheduleApplication.main(PikaScheduleApplication.java:38)
	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)
Caused by: java.lang.NoSuchMethodException: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceWrapper.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.getConstructor(Class.java:1825)
	at org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:113)
	at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
	at org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.DataSourceRegistry.getDataSource(DataSourceRegistry.java:61)
	at org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.DataSourceConfiguration.getStorage(DataSourceConfiguration.java:102)
	at org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.DataSourceConfiguration.getStorage(DataSourceConfiguration.java:43)
	at org.apache.shardingsphere.elasticjob.tracing.listener.TracingListenerFactory.getListener(TracingListenerFactory.java:56)
	at org.apache.shardingsphere.elasticjob.tracing.JobTracingEventBus.register(JobTracingEventBus.java:67)
	at org.apache.shardingsphere.elasticjob.tracing.JobTracingEventBus.<init>(JobTracingEventBus.java:55)
	at org.apache.shardingsphere.elasticjob.lite.internal.schedule.LiteJobFacade.<init>(LiteJobFacade.java:71)
	at org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobScheduler.<init>(JobScheduler.java:86)
	at org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap.<init>(ScheduleJobBootstrap.java:36)
	at org.apache.shardingsphere.elasticjob.lite.spring.boot.job.ElasticJobBootstrapConfiguration.registerClassedJob(ElasticJobBootstrapConfiguration.java:101)
	at org.apache.shardingsphere.elasticjob.lite.spring.boot.job.ElasticJobBootstrapConfiguration.constructJobBootstraps(ElasticJobBootstrapConfiguration.java:84)
	at org.apache.shardingsphere.elasticjob.lite.spring.boot.job.ElasticJobBootstrapConfiguration.createJobBootstrapBeans(ElasticJobBootstrapConfiguration.java:57)
	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.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157)
	... 23 common frames omitted

Disconnected from the target VM, address: '127.0.0.1:52855', transport: 'socket'

Process finished with exit code 0

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details.
If no response anymore and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ElasticJob did you use?

Which project did you use? ElasticJob-Lite or ElasticJob-Cloud?

Expected behavior

Actual behavior

Reason analyze (If you can)

Steps to reproduce the behavior.

Example codes for reproduce this issue (such as a github link).

@TeslaCN TeslaCN added the tracing label Jan 3, 2021
@TeslaCN
Copy link
Member

TeslaCN commented Jan 4, 2021

Hi @wenlincheng
We didn't take the wrapper class without public no args constructor into consideration before. Do you have any ideas about this issue?

@sandyisone
Copy link

有解决吗?

@skaic
Copy link
Contributor

skaic commented May 21, 2021

you can try register a bean of TracingConfiguration<DataSource> to cover default DruidDataSourceWrapper like this:

import org.apache.commons.dbcp2.BasicDataSource;

@Setter
@Configuration
@ConfigurationProperties(prefix = "elasticjob.tracing.datasource")
public class ElasticJobTracingConfiguration {

    private String driverClassName;

    private String url;

    private String username;

    private String password;

    @Bean
    public TracingConfiguration<DataSource> myTracingConfiguration() {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return new TracingConfiguration<>("RDB", dataSource);
    }

}

and

in application.yml

elasticjob:
  tracing:
    datasource:
      driverClassName: com.mysql.jdbc.Driver
      url: jdbc:mysql://xxxx/databases?useUnicode=true&characterEncoding=UTF-8&useSSL=false
      username: root
      password: xxxx

@folochina
Copy link

同样问题

  • elasticjob-lite-spring-boot-starter 3.0.0
  • springboot 2.3.2.RELEASE
  • druid-starter 1.2.6

@folochina
Copy link

您可以尝试注册一个 TracingConfiguration bean 来覆盖默认值, DruidDataSourceWrapper 如下所示:

import org.apache.commons.dbcp2.BasicDataSource;

@Setter
@Configuration
@ConfigurationProperties(prefix = "elasticjob.tracing.datasource")
public class ElasticJobTracingConfiguration {

    private String driverClassName;

    private String url;

    private String username;

    private String password;

    @Bean
    public TracingConfiguration<DataSource> myTracingConfiguration() {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return new TracingConfiguration<>("RDB", dataSource);
    }

}

application.yml

elasticjob:
  tracing:
    datasource:
      driverClassName: com.mysql.jdbc.Driver
      url: jdbc:mysql://xxxx/databases?useUnicode=true&characterEncoding=UTF-8&useSSL=false
      username: root
      password: xxxx

尝试了这个方案,发现无效

@MoonNi1ght
Copy link

MoonNi1ght commented Jan 10, 2022

hello, you can register a bean of TracingConfiguration to cover default DruidDataSourceWrapper

    @Bean
    public TracingConfiguration<DataSource> tracingConfiguration(final DataSource dataSource) {
        String className = "com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceWrapper";
        if (dataSource.getClass().getName().equals(className)) {
            DruidDataSource originDataSource = (DruidDataSource) dataSource;
            DruidDataSource selfDatasource = new DruidDataSource();
            //   set you datasource config
           selfDatasource.setDriver(originDataSource.getDriver());
           selfDatasource.setUrl(originDataSource.getUrl());
           selfDatasource.setUsername(originDataSource.getUsername());
           selfDatasource.setPassword(originDataSource.getPassword());
            return new TracingConfiguration<>(RDB, selfDatasource);
        }
        return new TracingConfiguration<>(RDB, dataSource);
    }

and do not have any config in application.yml about tarcing.

@71xian
Copy link

71xian commented Jan 23, 2022

alibaba/druid#4481

更新版本到1.2.8

@linghengqian
Copy link
Member

  • This issue is resolved in Alibaba Druid 1.2.8.

@linghengqian linghengqian added the dependencies Pull requests that update a dependency file label Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file tracing
Projects
None yet
Development

No branches or pull requests

8 participants