国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

SpringBoot 整合 Neo4j、MySQL 多數(shù)據(jù)源方案(Druid Mybatis DynamicDatasource)

這篇具有很好參考價值的文章主要介紹了SpringBoot 整合 Neo4j、MySQL 多數(shù)據(jù)源方案(Druid Mybatis DynamicDatasource)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

00 概述

本文總結(jié)了Neo4j和Spring/SpringBoot、Alibaba Druid、Dynamic Datasource、Mybatis等整合方案,對相應(yīng)配置做了詳細(xì)說明。

01 Spring Data Neo4j 整合方案


添加Neo4j JDBC Driver依賴

<!--Neo4j-Jdbc-Driver-->
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-jdbc-driver</artifactId>
    <version>4.0.5</version>
</dependency>

添加application.yml配置

spring:
    neo4j:
      uri: bolt://localhost:7687 # neo4j+s://xxx.xxx.xxx
      authentication:
        username: neo4j
        password: root

02 Alibaba Druid 整合方案


添加Neo4j JDBC Driver + Alibaba Druid依賴

<!--Neo4j-Jdbc-Driver-->
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-jdbc-driver</artifactId>
    <version>4.0.5</version>
</dependency>
<!--Druid-->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.2.12</version>
</dependency>

添加application.yml配置

spring:
    datasource:
      type: com.alibaba.druid.pool.DruidDataSource
      driverClassName: org.neo4j.jdbc.Driver
      url: jdbc:neo4j:bolt://localhost:7687 #jdbc:neo4j:neo4j+s://xxx.xxx.xxx
      username: neo4j
      password: root

03 Dynamic Datasource 多數(shù)據(jù)源整合方案


添加Neo4j JDBC Driver、Alibaba Druid、Dynamic DataSource依賴

<!--Neo4j-Jdbc-Driver-->
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-jdbc-driver</artifactId>
    <version>4.0.5</version>
</dependency>
<!--Druid-->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.2.12</version>
</dependency>
<!-- Dynamic DataSource -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
    <version>3.5.2</version>
</dependency>
<!--Mybatis SpringBoot-->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.2.2</version>
</dependency>

添加application.yml配置

spring:
  datasource:
    druid:
      initialSize: 5
      minIdle: 5
      maxActive: 20
      maxWait: 60000
      timeBetweenEvictionRunsMillis: 60000
      minEvictableIdleTimeMillis: 300000
      testOnBorrow: false
      testOnReturn: false
      poolPreparedStatements: true
      filters: stat,wall,slf4j
      maxPoolPreparedStatementPerConnectionSize: 20
      useGlobalDataSourceStat: true
      connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
    dynamic:
      datasource:
        # Mysql Datasource
        master:
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://127.0.0.1:3306/master
          username: root
          password: root
        # Neo4j Datasource
        neo4j:
          driver-class-name: org.neo4j.jdbc.Driver
          url: jdbc:neo4j:bolt://localhost:7687 #jdbc:neo4j:neo4j+s://xxx.xxx.xxx
          username: neo4j
          password: root
  # Neo4j Setting
  neo4j:
    uri: bolt://localhost:7687 #neo4j+s://xxx.xxx.xxx
    authentication:
      username: neo4j
      password: root

Mapper中加入數(shù)據(jù)源注解:@DS("neo4j")

@DS("neo4j")
@Repository
public interface Neo4jTestMapper {
    List<SysDept> selectMovies();
}

Mapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.kevinwong.mapper.Neo4jTestMapper">

    <select id="selectMovies" resultType="MovieInfo">
        MATCH (people:Movie)
        RETURN
          id(people) as id,
          people.title as title,
          people.tagline as tagline,
          people.released as released LIMIT 10
    </select>

</mapper>

查詢?nèi)罩荆?/p>

JDBC Connection [com.baomidou.dynamic.datasource.tx.ConnectionProxy@501a99e2] will not be managed by Spring
==>  Preparing: MATCH (people:Movie) RETURN id(people) as id, people.title as title, people.tagline as tagline, people.released as released LIMIT 10
==> Parameters: 
<==    Columns: id, title, tagline, released
<==        Row: 0, The Matrix, Welcome to the Real World, 1999
<==        Row: 9, The Matrix Reloaded, Free your mind, 2003
.........

<==        Row: 56, What Dreams May Come, After life there is more. The end is just the beginning., 1998
<==      Total: 10
Committing JDBC Connection [com.baomidou.dynamic.datasource.tx.ConnectionProxy@501a99e2]

04 注意事項


1.datasource中driver的配置

本文driverClassName配置為org.neo4j.jdbc.Driver,方便在uri變化時自動匹配不同driver。neo4j-jdbc-driver提供了HttpDriver、BoltDriver、BoltRoutingNeo4jDriver三種不同Scheme下的驅(qū)動,uri前綴不同時需要配置相應(yīng)的driver,配置出錯會產(chǎn)生連接異常。org.neo4j.jdbc.Driver下初始化了三種driver,根據(jù)uri配置的前綴自動匹配。

static {
    DRIVERS.put("^neo4j(\\+s|\\+ssc)?$", BoltRoutingNeo4jDriver.class);
    DRIVERS.put("^bolt(\\+s|\\+ssc)?$", BoltDriver.class);
    DRIVERS.put("http[s]?", HttpDriver.class);
}

2.Dynamic Datasource 多數(shù)據(jù)源的配置

在多數(shù)據(jù)源配置中,在spring.dynamic.datasource下配置了neo4j數(shù)據(jù)源, 仍然配置了spring.neo4j相關(guān)參數(shù),主要原因為Neo4jDriver會在啟動時進(jìn)行健康檢查,如果不配置會產(chǎn)生健康檢查失敗告警:WARN o.s.b.actuate.neo4j.Neo4jReactiveHealthIndicator - Health check failed文章來源地址http://www.zghlxwxcb.cn/news/detail-403376.html

2022-10-10 10:10:00 [Neo4jDriverIO-2-3] WARN  o.s.b.actuate.neo4j.Neo4jReactiveHealthIndicator - Health check failed 
org.neo4j.driver.exceptions.AuthenticationException: Unsupported authentication token, scheme='none' only allowed when auth is disabled: { scheme='none', user_agent='neo4j-java/dev' }
at org.neo4j.driver.internal.util.ErrorUtil.newNeo4jError(ErrorUtil.java:76)
at org.neo4j.driver.internal.async.inbound.InboundMessageDispatcher.handleFailureMessage(InboundMessageDispatcher.java:122)
    .........

at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:750)
Suppressed: org.neo4j.driver.exceptions.ServiceUnavailableException: Connection to the database terminated. Please ensure that your database is listening on the correct host and port and that you have compatible encryption settings both on Neo4j server and driver. Note that the default encryption setting has changed in Neo4j 4.0.
at org.neo4j.driver.internal.util.ErrorUtil.newConnectionTerminatedError(ErrorUtil.java:56)
    .........

到了這里,關(guān)于SpringBoot 整合 Neo4j、MySQL 多數(shù)據(jù)源方案(Druid Mybatis DynamicDatasource)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • springboot整合neo4j模糊查詢

    1.場景 查詢與content相似的實體 解決方案: 1.直接從neo4j中查詢所有實體并使用杰卡德相似度算法計算相似度,返回top n,該方案由于要匹配圖中所有實體,性能較差。 2.模糊查詢neo4j中的實體,并對查詢結(jié)果與content做相似度計算,相似度算法為hutool中的TextSimilarity.similar()接口

    2024年02月13日
    瀏覽(23)
  • 圖數(shù)據(jù)庫_Neo4j和SpringBoot整合使用_創(chuàng)建節(jié)點_刪除節(jié)點_創(chuàng)建關(guān)系_使用CQL操作圖譜---Neo4j圖數(shù)據(jù)庫工作筆記0009

    圖數(shù)據(jù)庫_Neo4j和SpringBoot整合使用_創(chuàng)建節(jié)點_刪除節(jié)點_創(chuàng)建關(guān)系_使用CQL操作圖譜---Neo4j圖數(shù)據(jù)庫工作筆記0009

    首先需要引入依賴 ? springboot提供了一個spring data neo4j來操作 neo4j ? 可以看到它的架構(gòu) ? 這個是下載下來的jar包來看看 有很多cypher對吧 ? 可以看到就是通過封裝的驅(qū)動來操作graph database ? 然后開始弄一下 首先添加依賴

    2024年02月12日
    瀏覽(25)
  • springboot整合neo4j-使用原生cypher

    該文的實現(xiàn)有更簡單的方式,詳見我的另一篇博客springboot整合neo4j–采用Neo4jClient和Neo4jTemplate方式 Neo4j 提供 JAVA API 以編程方式執(zhí)行所有數(shù)據(jù)庫操作。它支持三種類型的API: 1、Neo4j 原生的 Java API 原生 Java API 是一種低級別的純 JAVA API,用于執(zhí)行數(shù)據(jù)庫操作。 2、Neo4j Cypher Jav

    2024年02月12日
    瀏覽(24)
  • 【微服務(wù)】springboot整合neo4j使用詳解

    在上一篇我們詳細(xì)了解了neo4j的使用,從搭建到相關(guān)的語法操作,本篇緊接著之前的內(nèi)容,來詳細(xì)聊聊如何在springboot應(yīng)用中集成和使用neo4j。 和很多其他的中間件類似,都提供了類似jpa的方式與springboot進(jìn)行集成,比如大家熟悉的springdata-jpa,操作es的jpa,操作mongo的jpa等,而

    2024年02月08日
    瀏覽(21)
  • springboot整合neo4j-使用原生cypher Java API

    該文的實現(xiàn)有更簡單的方式,詳見我的另一篇博客springboot整合neo4j–采用Neo4jClient和Neo4jTemplate方式 Neo4j 提供 JAVA API 以編程方式執(zhí)行所有數(shù)據(jù)庫操作。它支持三種類型的API: 1、Neo4j 原生的 Java API 原生 Java API 是一種低級別的純 JAVA API,用于執(zhí)行數(shù)據(jù)庫操作。 2、Neo4j Cypher Jav

    2024年02月09日
    瀏覽(23)
  • 圖數(shù)據(jù)庫Neo4j——SpringBoot使用Neo4j & 簡單增刪改查 & 復(fù)雜查詢初步

    圖數(shù)據(jù)庫Neo4j——SpringBoot使用Neo4j & 簡單增刪改查 & 復(fù)雜查詢初步

    圖形數(shù)據(jù)庫是專門用于存儲圖形數(shù)據(jù)的數(shù)據(jù)庫,它使用圖形模型來存儲數(shù)據(jù),并且支持復(fù)雜的圖形查詢。常見的圖形數(shù)據(jù)庫有Neo4j、OrientDB等。 Neo4j是用Java實現(xiàn)的開源NoSQL圖數(shù)據(jù)庫,本篇博客介紹如何在SpringBoot中使用Neo4j圖數(shù)據(jù)庫,如何進(jìn)行簡單的增刪改查,以及如何進(jìn)行復(fù)雜

    2024年02月06日
    瀏覽(33)
  • Springboot項目連接neo4j數(shù)據(jù)庫

    首先創(chuàng)建一個springboot項目,這里不再介紹。 連接 neo4j 數(shù)據(jù)庫的依賴包 spring-boot-starter-data-neo4j依賴包 mybatis-plus依賴包

    2024年02月12日
    瀏覽(23)
  • Spring Boot整合neo4j

    Spring Boot整合neo4j

    相關(guān)版本信息 1、配置文件 Pom文件中引入依賴 Spring生態(tài)中Spring-data部分不僅僅提供了Spring-data-jpa , 也提供了Spring-data-neo4j 支持spring和 neo4j的完美融合,pom.xml 文件中依賴 yml文件中配置連接屬性 2、實體類(NodeEntity) @NodeEntity: 標(biāo)明是一個節(jié)點實體@RelationshipEntity:標(biāo)明是一個

    2024年02月10日
    瀏覽(18)
  • SpringBoot版本和Neo4j圖數(shù)據(jù)庫版本對應(yīng)關(guān)系

    Neo4j OGM Version Neo4j Version Bolt Version# Spring Data Neo4j Version Spring Boot Version 3.1.0+ 3.1.x, 3.2.x, 3.3.x 1.5.0+ (compatible with 1.4.0+) 5.1.0+ (compatible with 5.0.0+) 2.0.0+ 3.0.0+ 3.1.x, 3.2.x, 3.3.x 1.4.0+ 5.0.0+ 2.0.0+ 2.1.0+ 2.3.x, 3.0.x, 3.1.x 1.1.0+ 4.2.0+ 1.5.0+ 2.0.2+ 2.3.x, 3.0.x 1.0.0+ 4.1.2 - 4.1.6+ 1.4.x 2.0.1* 2.2.x, 2.3.x 1.0.0-

    2024年02月09日
    瀏覽(22)
  • springboot+neo4j

    請通過依賴項管理包含啟動器模塊并配置要使用的 Bolt URL,例如 spring.neo4j.uri=bolt://localhost:7687 。啟動器假設(shè)服務(wù)器已禁用身份驗證。由于 SDN 啟動器依賴于 Java 驅(qū)動程序的啟動器,因此此處所說的有關(guān)配置的所有內(nèi)容也適用于此處。有關(guān)可用屬性的參考,請在 spring.neo4j 命名

    2024年01月20日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包