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

springboot2.x+ elasticjo3.0.0-RC1 +mybatis-dynamic3.3.0, can not work well with elasticjob.tracing.type=RDB #1865

Closed
double2013 opened this issue Apr 1, 2021 · 7 comments

Comments

@double2013
Copy link

application.yml as below:

spring:
  application:
    name: job-common-executor
  datasource:
#    url: jdbc:mysql://192.168.255.102:3306/elastic_job_demo?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
#    username: xxxxx
#    password: xxxxxx
#    driver-class-name: com.mysql.cj.jdbc.Driver
    druid:
      stat-view-servlet:
        enabled: true
        login-username: admin
        login-password: 123456
    dynamic:
      druid:
        initial-size: 5
        max-active: 20
        min-idle: 5
        max-wait: 60000
        time-between-eviction-runs-millis: 60000
        time-between-log-stats-millis:
        stat-sqlmax-size:
        min-evictable-idle-time-millis: 300000
        max-evictable-idle-time-millis:
        test-while-idle: true
        test-on-borrow: false
        test-on-return: false
        validation-query: SELECT 1
        validation-query-timeout:
        use-global-datasource-stat:
        async-init:
        clear-filters-enable:
        reset-stat-enable:
        not-full-timeout-retry-count:
        max-wait-thread-count:
        fail-fast:
        phyTimeout-millis:
        keep-alive:
        pool-prepared-statements:
        init-variants:
        init-global-variants:
        use-unfair-lock:
        kill-when-socket-read-timeout:
        connection-properties:
        max-pool-prepared-statement-per-connection-size: 20
        init-connection-sqls:
        share-prepared-statements:
        connection-errorretry-attempts:
        break-after-acquire-failure:
        filters: stat,wall 
        stat:
          merge-sql:
          log-slow-sql:
          slow-sql-millis:
      primary: dmsdb
      strict: false
      datasource:
        nabftooldb:
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://xxxx:3306/NABFTOOLS1?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
          username: xxxx
          password: xxxxx
        dmsdb:
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://xxxxx:3306/DMS?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
          username: xxxxx
          password: xxxxx


server:
  port: 8083

logging:
  config: classpath:logback.xml

elasticjob:
#  tracing:
#    type: RDB
  regCenter:
    serverLists: 192.168.255.102:2181
    namespace: job-common
    maxSleepTimeMilliseconds: 30000
  jobs:
    MailAutoSendJob:
      elasticJobClass: com.job.common.executor.jobhandler.MailAutoSendJob
      cron: 0/10 * * * * ?
      shardingTotalCount: 1
      shardingItemParameters:

if i open elasticjob.tracing.type , like below, then application will throw exception, otherwise it work well.

spring:
  application:
    name: job-common-executor
  datasource:
    url: jdbc:mysql://192.168.255.102:3306/elastic_job_demo?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
    username: xxxxx
    password: xxxxxx
    driver-class-name: com.mysql.cj.jdbc.Driver
    druid:
      stat-view-servlet:
        enabled: true
        login-username: admin
        login-password: 123456
   .......


server:
  port: 8083

logging:
  config: classpath:logback.xml

elasticjob:
  tracing:
    type: RDB
  .......

18:25:57.644 logback [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: 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.NullPointerException
18:25:57.644 logback [main] INFO c.b.d.d.DynamicRoutingDataSource - dynamic-datasource start closing ....
18:25:57.647 logback [main] INFO c.alibaba.druid.pool.DruidDataSource - {dataSource-1} closing ...
18:25:57.650 logback [main] INFO c.alibaba.druid.pool.DruidDataSource - {dataSource-1} closed
18:25:57.650 logback [main] INFO c.alibaba.druid.pool.DruidDataSource - {dataSource-2} closing ...
18:25:57.651 logback [main] INFO c.alibaba.druid.pool.DruidDataSource - {dataSource-2} closed
18:25:57.651 logback [main] INFO c.alibaba.druid.pool.DruidDataSource - {dataSource-3} closing ...
18:25:57.653 logback [main] INFO c.alibaba.druid.pool.DruidDataSource - {dataSource-3} closed
18:25:57.653 logback [main] INFO c.b.d.d.DynamicRoutingDataSource - dynamic-datasource all closed success,bye
18:25:58.155 logback [Curator-Framework-0] INFO o.a.c.f.imps.CuratorFrameworkImpl - backgroundOperationsLoop exiting
18:25:58.177 logback [main-SendThread(192.168.255.102:2181)] WARN org.apache.zookeeper.ClientCnxn - An exception was thrown while closing send thread for session 0x3f9a1ce0008.
org.apache.zookeeper.ClientCnxn$EndOfStreamException: Unable to read additional data from server sessionid 0x3f9a1ce0008, likely server has closed socket
at org.apache.zookeeper.ClientCnxnSocketNIO.doIO(ClientCnxnSocketNIO.java:75)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:348)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1262)
18:25:58.280 logback [main] INFO org.apache.zookeeper.ZooKeeper - Session: 0x3f9a1ce0008 closed
18:25:58.280 logback [main-EventThread] INFO org.apache.zookeeper.ClientCnxn - EventThread shut down for session: 0x3f9a1ce0008
18:25:58.288 logback [main] INFO o.s.b.a.l.ConditionEvaluationReportLoggingListener -

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
18:25:58.307 logback [main] ERROR 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.NullPointerException
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:422)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213)
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:270)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:762)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:567)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:769)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1313)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302)
at com.job.common.executor.LemesJobCommonExecutorApplication.main(LemesJobCommonExecutorApplication.java:13)
Caused by: java.lang.NullPointerException: null
at com.baomidou.dynamic.datasource.ds.AbstractRoutingDataSource.getConnection(AbstractRoutingDataSource.java:44)
at org.apache.shardingsphere.elasticjob.tracing.rdb.storage.RDBJobEventStorage.getDatabaseType(RDBJobEventStorage.java:79)
at org.apache.shardingsphere.elasticjob.tracing.rdb.storage.RDBJobEventStorage.(RDBJobEventStorage.java:73)
at org.apache.shardingsphere.elasticjob.tracing.rdb.listener.RDBTracingListener.(RDBTracingListener.java:36)
at org.apache.shardingsphere.elasticjob.tracing.rdb.listener.RDBTracingListenerConfiguration.createTracingListener(RDBTracingListenerConfiguration.java:35)
at org.apache.shardingsphere.elasticjob.tracing.rdb.listener.RDBTracingListenerConfiguration.createTracingListener(RDBTracingListenerConfiguration.java:30)
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.(JobTracingEventBus.java:55)
at org.apache.shardingsphere.elasticjob.lite.internal.schedule.LiteJobFacade.(LiteJobFacade.java:71)
at org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobScheduler.(JobScheduler.java:86)
at org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap.(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)
... 19 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:30528', transport: 'socket'

Process finished with exit code 1

pom.xml as below:

<mybatis-plus.version>3.1.2</mybatis-plus.version>
<mybatis-dynamic.version>3.3.0</mybatis-dynamic.version>
<elasticjob.version>3.0.0-RC1</elasticjob.version>

<dependency>
	<groupId>com.baomidou</groupId>
	<artifactId>mybatis-plus-boot-starter</artifactId>
	<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
	<groupId>com.baomidou</groupId>
	<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
	<version>${mybatis-dynamic.version}</version>
</dependency>
<dependency>
	<groupId>com.alibaba</groupId>
	<artifactId>druid-spring-boot-starter</artifactId>
	<version>${druid.version}</version>
</dependency>
@skaic
Copy link
Contributor

skaic commented May 10, 2021

you can register a bean of TracingConfiguration<DataSource> like this:

@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

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

@ArberChang
Copy link

        <dependency>
            <groupId>org.apache.shardingsphere.elasticjob</groupId>
            <artifactId>elasticjob-lite-spring-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

it dosen`t work,when i change version to 3.0.0

@yujun-8848
Copy link

i have tried to it,but it not work well,Have you solved it now?

@sunshaohua0221
Copy link

I also encountered the same problem, the problem is not solved, version:3.0.1, the error is as follows:
Parameter 0 of method tracingConfiguration in org.apache.shardingsphere.elasticjob.lite.spring.boot.tracing.ElasticJobTracingConfiguration required a single bean, but 2 were found:
- master: defined by method 'master' in class path resource [com/jdcloud/cost/service/config/DruidConfig.class]
- slave: defined by method 'slave' in class path resource [com/jdcloud/cost/service/config/DruidConfig.class]

@Xiejinhua123
Copy link

I'm going to rewrite TracingConfiguration about the Springboot partial integration, but it always prompts that two identical types appear. It is always not possible to configure a data source dedicated to the job task.Now, I don't know what to do!

@linghengqian
Copy link
Member

I can't reproduce this issue with Spring Boot 3.3.2 in master branch, see #2417. Please provide unit tests.

@linghengqian linghengqian closed this as not planned Won't fix, can't repro, duplicate, stale Aug 20, 2024
@linghengqian
Copy link
Member

Closed because it could not be reproduced.

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

No branches or pull requests

8 participants