问题说明:
我们项目中使用到了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