grails与neo4j不兼容

时间:2015-10-11 04:47:10

标签: grails neo4j gorm grails-3.0 nosql

我正在尝试使用grails和neo4j开发一个示例应用程序。我使用的是grails 3.0.8。我已经安装了neo4j插件,并按照文档中提到的说明进行操作。我已经更新了application.yml以包含neo4j凭据。我的application.yml看起来像这样。

    ---
grails:
    profile: web
    codegen:
    defaultPackage: sftwitter
info:
    app:
    name: '@info.app.name@'
    version: '@info.app.version@'
    grailsVersion: '@info.app.grailsVersion@'
spring:
    groovy:
    template:
        check-template-location: false

---
grails:
    mime:
    disable:
        accept:
            header:
                userAgents:
                    - Gecko
                    - WebKit
                    - Presto
                    - Trident
    types:
        all: '*/*'
        atom: application/atom+xml
        css: text/css
        csv: text/csv
        form: application/x-www-form-urlencoded
        html:
          - text/html
          - application/xhtml+xml
        js: text/javascript
        json:
          - application/json
          - text/json
        multipartForm: multipart/form-data
        pdf: application/pdf
        rss: application/rss+xml
        text: text/plain
        hal:
          - application/hal+json
          - application/hal+xml
        xml:
          - text/xml
          - application/xml
    urlmapping:
    cache:
        maxsize: 1000
    controllers:
    defaultScope: singleton
    converters:
    encoding: UTF-8
    views:
    default:
        codec: html
    gsp:
        encoding: UTF-8
        htmlcodec: xml
        codecs:
            expression: html
            scriptlets: html
            taglib: none
            staticparts: none
---
grails:
    neo4j:
    type: rest
    location: http://localhost:7474/db/data/
    username: neo4j
    password: welcome123

hibernate:
    cache:
    queries: false
    use_second_level_cache: true
    use_query_cache: false
    region.factory_class: 'org.hibernate.cache.ehcache.EhCacheRegionFactory'

endpoints:
    jmx:
    unique-names: true

dataSource:
    pooled: true
    jmxExport: true
    driverClassName: org.h2.Driver
    username: sa
    password:

environments:
    development:
    dataSource:
        username: neo4j
        password: welcome123
        dbCreate: create-drop
        url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    test:
    dataSource:
        dbCreate: update
        url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    production:
    dataSource:
        dbCreate: update
        url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
        properties:
            jmxEnabled: true
            initialSize: 5
            maxActive: 50
            minIdle: 5
            maxIdle: 25
            maxWait: 10000
            maxAge: 600000
            timeBetweenEvictionRunsMillis: 5000
            minEvictableIdleTimeMillis: 60000
            validationQuery: SELECT 1
            validationQueryTimeout: 3
            validationInterval: 15000
            testOnBorrow: true
            testWhileIdle: true
            testOnReturn: false
            jdbcInterceptors: ConnectionState
            defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED

代码执行正常,但是当我尝试创建域的实例时,我得到这样的错误。

ERROR org.grails.web.errors.GrailsExceptionResolver - IllegalStateException occurred when processing request: [GET] /person/index
Method on class [neo4j.Person] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.. Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_60]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_60]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]
Caused by: java.lang.IllegalStateException: Method on class [neo4j.Person] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
    at neo4j.PersonController.index(PersonController.groovy:13) ~[main/:na]
    at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:93) ~[grails-core-3.0.8.jar:3.0.8]
    at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:90) ~[grails-core-3.0.8.jar:3.0.8]
    ... 3 common frames omitted

我完全根据文档完成了此配置,那么为什么我会收到此错误。是不是新版本的grails与neo4j存在兼容性问题,还是我在配置中犯了一些错误。

0 个答案:

没有答案