Bean 验证不起作用 Spring Data Neo4j

2023-12-05

我正在使用带有嵌入式 Neo4j 的 SDN。我必须使用 bean validate,但它不起作用。null 毫无例外地保存在数据库中。

依赖性是

dependencies {
    // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
    // runtime 'mysql:mysql-connector-java:5.1.29'
    // runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
    test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
    compile 'org.springframework.data:spring-data-neo4j:3.2.0.RELEASE'
    compile 'org.hibernate:hibernate-validator:4.3.1.Final'
    compile 'javax.validation:validation-api:1.0.0.GA'      
}

xml config is 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/neo4j
http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd">
<context:component-scan base-package="neo4j"></context:component-scan>
<neo4j:config
storeDirectory="target/db2"
base-package="neo4j"/>

<bean id="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>

<neo4j:repositories base-package="neo4j" />
</beans>

实体类

@NodeEntity
class Role {
    @GraphId Long graphId

    @NotNull
    String name;

}

控制器是

@Transactional
    def saveUser(){

        println "in saveUser"
        Role role = new Role();
        Neo4jTemplate.save(role);

    }

我正在使用 spring-data-neo4j 3.2.0.RELEASE


介绍

????Spring数据Neo4j 6.x(您使用导入 spring-boot-starter-parent:2.4.x 的那个)消除了直接从域模型创建约束的可能性.

现在,这意味着您必须使用 Neo4j 的 Cypher 查询语言并执行您想要执行的操作(例如:CREATE CONSTRAINT notnull_name IF NOT EXISTS ON (role:Role) ASSERT EXISTS (role.name) ).

显然,这很难管理,因为您必须在应用程序启动之前执行脚本。而且对于生产环境来说是有困难的。

????So 版画已经创建:它是一个为我们执行脚本的工具。

该机制如下,我报告这一点issue在 Github 上,它很好地解释了一切。


Solution

???? Pom.xml 依赖项:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-jdbc-driver</artifactId>
    <version>4.0.1</version>
</dependency>
<dependency>
    <groupId>org.liquigraph</groupId>
    <artifactId>liquigraph-spring-boot-starter</artifactId>
    <version>4.0.2</version>
</dependency>

???? 变更日志.xml 文件(位于此处 -> {project_dir}/src/main/resources/db/liquigraph/changelog.xml):

<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns="http://www.liquigraph.org/schema/1.0/liquigraph.xsd">
    <changeset id="constraints" author="you">
        <query>CREATE CONSTRAINT notnull_name IF NOT EXISTS ON (role:Role) ASSERT EXISTS (role.name)</query>
    </changeset>
</changelog>

???? application.yml 属性:

spring:
  neo4j:
    uri: neo4j://localhost:7687                           #neo4j+s if you use an HTTPS Neo4j instance
    authentication:
      username: neo4j
      password: neo4j
  datasource:                                             #Liquigraph configuration used by Liquigraph POM dependency
    url: jdbc:neo4j:neo4j://localhost?encryption=false    #encryption=true if you use an HTTPS Neo4j instance
    driver-class-name: org.neo4j.jdbc.boltrouting.BoltRoutingNeo4jDriver
    username: neo4j
    password: neo4j

✔️ ## 在启动时,将创建以下约束##

具体日志:

2021-01-12 18:33:18.917  INFO 2420 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-01-12 18:33:18.940  INFO 2420 --- [           main] Driver                                   : Routing driver instance 706067443 created for server address localhost:7687
2021-01-12 18:33:21.510  INFO 2420 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-01-12 18:33:22.672  INFO 2420 --- [           main] o.l.core.io.ChangelogGraphWriter         : Executing postcondition of changeset ID constraints by you
2021-01-12 18:33:22.775  INFO 2420 --- [           main] o.l.core.io.ChangelogGraphWriter         : Changeset ID constraints by you was just executed

正如你所看到的,你的changelog.xml已经被应用了✔️。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Bean 验证不起作用 Spring Data Neo4j 的相关文章

随机推荐

  • Python子进程和用户交互

    我正在 Python 2 6 中开发 GUI 前端 通常它相当简单 你使用subprocess call or subprocess Popen 发出命令并等待其完成或对错误做出反应 如果您的程序停止并等待用户交互 您会怎么做 例如 程序可
  • 升级 python 图像库 (PIL) 时,它告诉我“JPEG 支持不可用”

    使用ubuntu 13 10 python 2 7 5 gt gt gt import imaging Image gt gt gt from PIL import Image ImageDraw ImageFilter ImageFont
  • 从http内部函数返回数据

    我在用着this and this参考 从函数内的 http 请求返回数据 function getdetails id var datafordetails data1 item1 item2 data2 item3 ID id var
  • 将项目视为邮件项目

    我正在 Outlook 2016 中创建一个 VBA 应用程序 它分析传入的电子邮件并获取其主题行来搜索重复 或接近重复 的主题行 我使用 for each 循环来浏览项目列表 收件箱中的电子邮件 并分析每个项目的标准 一旦需要回复 传入的
  • R strptime 来自周数的星期一日期很奇怪

    我在这里犯了一个小错误 但无法集中精力找出问题所在 我需要获取随机日期的星期一的日期 似乎我得到了完全不同的东西 mydate lt date 2013 11 05 format mydate A this is Tuesday right
  • 流畅和查询表达式——其中一种比另一种有什么好处吗? [关闭]

    Closed 这个问题是基于意见的 目前不接受答案 LINQ 是自泛型以来对 NET 最伟大的改进之一 它为我节省了大量的时间和代码行 然而 对我来说 流畅的语法似乎比查询表达式语法更自然 var title entries Where e
  • 强制 MS Access 检索所有列表框行并释放锁定

    我有一个列表框 其中 RowSource 绑定到附加的 SQL Server 表 如果表很大 Access 不会加载完整的结果集 而是创建服务器端游标并在列表框向下滚动时 按需 加载数据 这是一个很好的功能 因为它允许列表框和组合框快速显示
  • jquery validate:为错误消息添加淡入/淡出效果

    我想为 jquery 验证上显示的错误消息添加淡入 淡出效果 有什么方法可以做到这一点 我可以在它们上使用 div 并单独处理它们吗 插件有这个效果吗 我使用此代码来放置错误消息 我需要它来正确放置 commentForm2 validat
  • NestJS TypeORM 模拟存储库的数据源

    我正在尝试模拟一个存储库 我不想进行实际的数据库调用 我 认为我 正在关注 NestJS 的文档以及某些 stackoverflow 项目 但是 当我运行测试时 出现以下错误 JwtStrategy validate throws an u
  • Java 7 支持的 JavaFx 应用程序未在 Mojave 上运行

    我的申请支持 Jdk1 7 0 76 JavaFx2 2 76 b13 Netbeans IDE Ant 用于构建和创建安装程序 在 Windows 和 Mac 上受支持 它一直成功运行到 High Sierra 当我尝试跑步时 app莫哈
  • 获取数据然后渲染到dom React

    您好 我正在从 api 获取数据 我想获取数据并将其渲染到 dom 但出现错误 Uncaught TypeError Cannot read property map of undefined at Topicselect render 这
  • CUDA 内核中的 2D 图像索引错误

    我正在使用 CUDA 对图像进行线性过滤 我使用 2D 线程块和 2D 网格来使问题变得自然 这是我的索引方式 height and width是图像尺寸 dim3 BlockDim 16 16 dim3 GridDim GridDim x
  • 以编程方式检测 iPhone 上是否安装了应用程序

    我处于这种情况 我必须在 iPhone 应用程序中显示一个按钮 其中显示 打开 myApp 如果设备上安装了 myApp 或 下载 myApp 如果设备上未安装 myApp 为此 我需要检测设备上是否安装了应用程序 具有已知的自定义 URL
  • jqgrid:添加表单需要但编辑表单不需要的字段?

    用户有密码 添加用户时需要密码 但在编辑操作时不需要密码 但可以更改 用jqgrid可以做到这一点吗 您可以更改的值required的财产编辑规则代替beforeShowForm see here 您可以使用设置列属性例如这样做 例如设置r
  • Javafx 2.0 中的自定义标题栏?

    有没有关于如何在 javafx 2 0 中创建自定义标题栏的教程 我正在创建一个桌面 GUI 应用程序 希望有一个黑色渐变标题栏 其中包含用于最小化和关闭的自定义按钮 Here是 WPF 的教程 我正在寻找类似于 javafx 的东西 隐藏
  • Powershell DSC:带有参数的复合资源不起作用

    我正在开发 DSC 复合资源 但我似乎无法让它工作 我的代码 E Dev DSCResources run ps1 Import Module Test Force Configuration Run Import DscResource
  • Ionic 4 中的冲突组件:IonCard 和 SwingCardComponent

    我正在关注本教程 并且我在 Ionic3 和 4 之间的差异方面面临一些困难 我正在使用 Ionic4 当我这样做时ionic serve一切都编译成功 但是当我转到网络浏览器时 控制台中出现以下错误 Uncaught Error Temp
  • 没有数据库的 ASP.NET MVC 角色(并且没有角色提供程序)

    我有一个超级简单的 ASP NET MVC 应用程序 它使用 RpxNow OpenID 来允许用户登录 我现在想让用户编辑自己的帐户 并提供管理员访问权限来编辑任何人的帐户 我有两个单独的 编辑帐户 视图 帐户 编辑 帐户 编辑 1 第一
  • 无法在 Windows 7 本地运行 Meteor 应用程序

    我在从命令提示符行运行我的应用程序时遇到问题 我不习惯从终端运行应用程序等 我将向您展示我在下面得到的内容 C Windows system32 gt meteor create newapp newapp created To run y
  • Bean 验证不起作用 Spring Data Neo4j

    我正在使用带有嵌入式 Neo4j 的 SDN 我必须使用 bean validate 但它不起作用 null 毫无例外地保存在数据库中 依赖性是 dependencies specify dependencies here under ei