解決elastic-job-ui在使用druid作為數(shù)據(jù)庫(kù)連接池時(shí)作業(yè)維度報(bào)錯(cuò)問題
問題說明
我們項(xiàng)目中使用到了elastic-job,然后自己封裝了個(gè)sdk,
方便使用,里面的數(shù)據(jù)源配置是常用的druid+mysql的組合,在操作中,發(fā)現(xiàn)elastic-job-ui可視化控制臺(tái)會(huì)報(bào)錯(cuò)無法使用。
深究其原因是因?yàn)?,各個(gè)服務(wù)把定時(shí)任務(wù)注冊(cè)到了zk中,包括數(shù)據(jù)庫(kù)配置類的一些信息,
但是elastic-job-ui源碼中沒有引入對(duì)應(yīng)的pom依賴,
導(dǎo)致他在去zk獲取了定時(shí)任務(wù)的配置類信息后,需要想這些信息轉(zhuǎn)換成對(duì)應(yīng)的類對(duì)象操作時(shí),沒法成功轉(zhuǎn)換。
解決
處理也很簡(jiǎn)單,
一種是項(xiàng)目中包裝的sdk不使用druid連接池即可,可以使用HikariCP,實(shí)測(cè)是沒問題
另一種更簡(jiǎn)單,下載elastic-job-ui源碼,在pom依賴中引入druid依賴接口(我們用這個(gè),省的改項(xiàng)目代碼,引用的地方太多了)
實(shí)操
下載源碼,使用的示最新的3.0.2版本
https://github.com/apache/shardingsphere-elasticjob-ui/tree/3.0.2
1、引入依賴和配置
引入druid依賴,順便mysql的也引入和配置下application,省的我們手動(dòng)配置mysql依賴文件了
另外他這個(gè)build也調(diào)整下,不然你直接對(duì)他打包才幾兆,不完整
<?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、打包
直接用這個(gè)打好的jar包,直接運(yùn)行即可,jar里面打包包含了前端頁(yè)面
3、訪問
java -jar運(yùn)行完這個(gè)jar包后,直接訪問 http://127.0.0.1:8088/#/ 即可看到可視化控制臺(tái)
賬號(hào)密碼都是默認(rèn)的root
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
java同步器AQS架構(gòu)AbstractQueuedSynchronizer原理解析
這篇文章主要為大家介紹了java同步器AQS架構(gòu)AbstractQueuedSynchronizer的底層原理及源碼解析,有需要的朋友可以借鑒參考下,希望能有所幫助,祝大家多多進(jìn)步早日升職加薪2022-03-03java快速排序和選擇排序?qū)崿F(xiàn)實(shí)例解析
這篇文章主要為大家介紹了java快速排序和選擇排序?qū)崿F(xiàn)實(shí)例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11spring.profiles.active配置使用小結(jié)
spring.profiles.active?配置使得應(yīng)用程序能夠在不同的環(huán)境中使用不同的配置,本文主要介紹了spring.profiles.active配置使用小結(jié),具有一定的參考價(jià)值,感興趣的可以了解一下2024-07-07Spring框架JdbcTemplate數(shù)據(jù)庫(kù)事務(wù)管理完全注解方式
這篇文章主要介紹了Spring框架JdbcTemplate數(shù)據(jù)庫(kù)事務(wù)管理及完全注解方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05Spring之ShutDown?Hook死鎖現(xiàn)象解讀
這篇文章主要介紹了Spring之ShutDown?Hook死鎖現(xiàn)象解讀,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04