elastic-job-ui在使用druid作为数据库连接池时作业维度报错

文章描述了一个项目中使用elastic-job并自封装SDK遇到的问题,由于elastic-job-ui源码未包含druid依赖,导致从Zookeeper获取的任务配置无法转换。解决方案是切换到HikariCP或直接修改elastic-job-ui源码,添加druid依赖。作者提供了具体的操作步骤,包括修改pom.xml文件,引入mysql和druid依赖,打包并运行新jar包,最后访问可视化控制台。
摘要由CSDN通过智能技术生成

问题说明:

我们项目中使用到了elastic-job,然后自己封装了个sdk,方便使用,里面的数据源配置是常用的druid+mysql的组合,在操作中,发现elastic-job-ui可视化控制台会报错无法使用。

深究其原因是因为,各个服务把定时任务注册到了zk中,包括数据库配置类的一些信息,但是elastic-job-ui源码中没有引入对应的pom依赖,导致他在去zk获取了定时任务的配置类信息后,需要想这些信息转换成对应的类对象操作时,没法成功转换。

解决:

处理也很简单,
一种是项目中包装的sdk不使用druid连接池即可,可以使用HikariCP,实测是没问题
另一种更简单,下载elastic-job-ui源码,在pom依赖中引入druid依赖接口(我们用这个,省的改项目代码,引用的地方太多了)

实操

下载源码,使用的示最新的3.0.2版本
https://github.com/apache/shardingsphere-elasticjob-ui/tree/3.0.2

1、引入依赖和配置

引入druid依赖,顺便mysql的也引入和配置下application,省的我们手动配置mysql依赖文件了
另外他这个build也调整下,不然你直接对他打包才几兆,不完整
在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
  ~ contributor license agreements.  See the NOTICE file distributed with
  ~ this work for additional information regarding copyright ownership.
  ~ The ASF licenses this file to You under the Apache License, Version 2.0
  ~ (the "License"); you may not use this file except in compliance with
  ~ the License.  You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-elasticjob-lite-ui</artifactId>
    <version>3.0.2</version>
</parent>
<artifactId>shardingsphere-elasticjob-lite-ui-backend</artifactId>
<name>${project.artifactId}</name>

<dependencies>
    <dependency>
        <groupId>org.apache.shardingsphere.elasticjob</groupId>
        <artifactId>elasticjob-lite-lifecycle</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.openjpa</groupId>
        <artifactId>openjpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-dbcp2</artifactId>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>javax.activation-api</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.13</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.22</version>
    </dependency>

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-core</artifactId>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
    </dependency>
    <dependency>
        <groupId>com.auth0</groupId>
        <artifactId>java-jwt</artifactId>
    </dependency>
</dependencies>

<build>
    <finalName>shardingsphere-elasticjob-lite-ui</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <configuration>
                <encoding>${project.build.sourceEncoding}</encoding>
                <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                <resources>
                    <resource>
                        <targetPath>${project.build.directory}/classes/public</targetPath>
                        <directory>${project.parent.basedir}/shardingsphere-elasticjob-lite-ui-frontend/dist</directory>
                    </resource>
                    <resource>
                        <targetPath>${project.build.directory}/classes</targetPath>
                        <directory>src/main/resources</directory>
                    </resource>
                </resources>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>${spring-boot.version}</version>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

application.properties文件直接加入mysql配置选择

## Uncomment the following property to allow adding DataSource dynamically.
dynamic.datasource.allowed-driver-classes={'org.h2.Driver','org.postgresql.Driver','com.mysql.cj.jdbc.Driver'}

2、打包

直接用这个打好的jar包,直接运行即可,jar里面打包包含了前端页面
在这里插入图片描述

3、访问

java -jar运行完这个jar包后,直接访问 http://127.0.0.1:8088/#/ 即可看到可视化控制台
账号密码都是默认的root
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值