解決elastic-job-ui在使用druid作為數(shù)據(jù)庫連接池時作業(yè)維度報錯問題
問題說明
我們項目中使用到了elastic-job,然后自己封裝了個sdk,
方便使用,里面的數(shù)據(jù)源配置是常用的druid+mysql的組合,在操作中,發(fā)現(xiàn)elastic-job-ui可視化控制臺會報錯無法使用。
深究其原因是因為,各個服務(wù)把定時任務(wù)注冊到了zk中,包括數(shù)據(jù)庫配置類的一些信息,
但是elastic-job-ui源碼中沒有引入對應(yīng)的pom依賴,
導(dǎo)致他在去zk獲取了定時任務(wù)的配置類信息后,需要想這些信息轉(zhuǎn)換成對應(yīng)的類對象操作時,沒法成功轉(zhuǎn)換。
解決
處理也很簡單,
一種是項目中包裝的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也調(diào)整下,不然你直接對他打包才幾兆,不完整

<?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

總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
java同步器AQS架構(gòu)AbstractQueuedSynchronizer原理解析
這篇文章主要為大家介紹了java同步器AQS架構(gòu)AbstractQueuedSynchronizer的底層原理及源碼解析,有需要的朋友可以借鑒參考下,希望能有所幫助,祝大家多多進步早日升職加薪2022-03-03
spring.profiles.active配置使用小結(jié)
spring.profiles.active?配置使得應(yīng)用程序能夠在不同的環(huán)境中使用不同的配置,本文主要介紹了spring.profiles.active配置使用小結(jié),具有一定的參考價值,感興趣的可以了解一下2024-07-07
Spring框架JdbcTemplate數(shù)據(jù)庫事務(wù)管理完全注解方式
這篇文章主要介紹了Spring框架JdbcTemplate數(shù)據(jù)庫事務(wù)管理及完全注解方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05
Spring之ShutDown?Hook死鎖現(xiàn)象解讀
這篇文章主要介紹了Spring之ShutDown?Hook死鎖現(xiàn)象解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04

