gpt4 book ai didi

rest - Grails 3.1.1 Rest-API和Neo4J 2.3基本示例不起作用

转载 作者:行者123 更新时间:2023-12-02 14:49:57 25 4
gpt4 key购买 nike

我试图通过对Neo4J的Gorm 5支持,以Neo4J作为数据库创建Grails 3.1.1项目。我使用rest-api配置文件创建了一个新的Grails项目。我已经添加了一个域类和该域类的静态 Controller 。

class User {

String firstName;

static constraints = {
}
}

class UserController extends RestfulController {
static responseFormats = ['json', 'xml']
UserController() {
super(User)
}
}

然后在 init/BootStrap.groovy文件中,添加了一些测试数据,保存后注销了id。
def init = { servletContext ->
User user1 = new User(firstName: "The Stand").save(flush:true);
User user2 = new User(firstName: "The Shining").save(flush:true);
log.info(user1.id);
log.info(user2.id);
}

在尝试将Neo4J用作我的数据库之前,一切正常。击中索引URL将显示用户:
[{"id":1,"firstName":"The Stand"},{"id":2,"firstName":"The Shining"}]

现在,我按照 http://grails.github.io/grails-data-mapping/latest/neo4j/manual/guide/gettingStarted.html#usingNeo4jStandalone中的说明进行操作

我按照说明2.1和2.4将Neo4J依赖项添加到build.gradle中。我假设我需要做2.4,因为grails 3.1使用spring boot启动。
compile "org.grails.plugins:neo4j:5.0.0.RC1"
compile "org.grails:gorm-neo4j-spring-boot:5.0.0.RC1"

我在同一文件中删除了hibernate插件:
compile "org.grails.plugins:hibernate4"

我没有为数据源添加任何配置,因此应按照说明使用基本的嵌入式neo4j实例。

对于指令2.4,我添加了@ComponentScan,尽管我的文件具有 GrailsApp.run并且指令具有 SpringApplication.run,所以这是不一致的。最后,我按照指令2.4将@Entity添加到User域类。

现在,当我重新启动应用程序时,我被告知 BootStrap记录已使用ID保存:
INFO grails.app.init.BootStrap - -8879732183286874112
INFO grails.app.init.BootStrap - -8879732183286833152

但是现在当我点击URL获取所有实例时,我得到了:
[]

而不是预期的:
[{"id":-8879732183286874112,"firstName":"The Stand"},{"id":-8879732183286833152,"firstName":"The Shining"}]

我尝试使用这些ID来访问show端点,但是什么也没有。我删除了2.4中建议的配置,但仍然没有。我尝试通过其余端点添加记录,但遇到其他问题和异常(exception),但这些问题和异常(exception)都没有什么用处。我在想,直到这些基本步骤不起作用,然后其他尝试不起作用也就不足为奇了。

从日志输出中看来,已添加了记录,但似乎我无法使应用程序检索它们。

有什么建议么?

最佳答案

我刚遇到问题。

尝试将其添加到您的域类中:

static mapping = {
id generator:'native'
}

关于rest - Grails 3.1.1 Rest-API和Neo4J 2.3基本示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35430437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com