Grails 2.4.3 + Neo4j Plugin =没有名为' sessionFactory'

时间:2014-12-14 18:13:27

标签: grails groovy intellij-idea

我想在Grails中使用Neo4J创建一个示例应用程序。 (在IntelliJ上)

创建一个简单的应用程序并在Buildconfig.groovy

中添加必要的配置

回购

mavenRepo 'http://m2.neo4j.org/content/repositories/releases/'

插件

    compile ":neo4j:2.0.0-M02"

我想同时使用MySql和Neo4J(在我想要neo4j的时候在域模型中添加映射)。

但我有这个错误:

 Error |
2014-12-14 19:05:59,261 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: No bean named 'sessionFactory' is defined
Message: No bean named 'sessionFactory' is defined
    Line | Method
->>  104 | postProcessBeanFactory in org.grails.datastore.gorm.plugin.support.PersistenceContextInterceptorAggregator

我做错了什么?

3 个答案:

答案 0 :(得分:1)

有同样的问题 - 如果我删除了neo4j插件 - 并创建一个普通的域类+测试工作正常

一旦启用neo4j插件(2.0.0-M2) - 并再次运行相同的测试,它就会失败并出现上述错误 -

不知道如何启用neo插件删除grails正常设置的sessionFactory bean

正在发生的事情

答案 1 :(得分:0)

试图欺骗并将其添加到resources.groovy beans

...
sessionFactory(ConfigurableLocalSessionFactoryBean) {
    dataSource = ref('dataSource')
    hibernateProperties = ["hibernate.hbm2ddl.auto": "create-drop",
                           "hibernate.show_sql":     "true"]
}

并尝试重新运行测试 - 仍然失败,因为它说错误

..Message: No such property: ConfigurableLocalSessionFactoryBean for class: resources

所以它在肠道深处......

答案 2 :(得分:0)

最后我找到了一个解决方案:不要使用这个插件。我更喜欢使用微服务架构。我用Spring Boot,Groovy和Neo4J创建了一个应用程序。我省略了控制器,模型和弹簧库。

build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.2.RELEASE")
    }
}


apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'


jar {
    baseName = "it.luis"
    version = '0.1-SNAPSHOT'
}



repositories {
    mavenCentral()
    jcenter()
    maven { url "http://m2.neo4j.org/content/repositories/releases/" }
    maven { url "https://repo.spring.io/libs-release" }
}

dependencies {
//    compile 'org.codehaus.groovy:groovy-all:2.4.0'
    compile localGroovy()
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter")
    compile("org.springframework:spring-context")
    compile("org.springframework:spring-tx")
    compile("org.springframework.data:spring-data-neo4j")
    compile("org.hibernate:hibernate-validator")
    compile("org.springframework.boot:spring-boot-starter-actuator")
    compile("javax.el:javax.el-api:2.2.4")
    testCompile("junit:junit")

    /* Swagger */
    compile "com.mangofactory:swagger-springmvc:0.9.5"

    /* Stormpath */
    compile "org.sonatype.oss:stormpath-spring-security"
    runtime "com.stormpath.sdk:stormpath-sdk-httpclient:0.9.3"
}

<强> Application.groovy

package it.luis

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.boot.autoconfigure.SpringBootApplication
/**
 * Created by Luigi on 01/03/2015.
 */
@SpringBootApplication
@EnableAutoConfiguration
class Application {



    public static void main(String[] args) {
        SpringApplication.run(Application.class,args)


    }
}

<强> Neo4JConf.groovy

package it.luis


import com.mangofactory.swagger.plugin.EnableSwagger
import org.neo4j.graphdb.GraphDatabaseService
import org.neo4j.graphdb.factory.GraphDatabaseFactory
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.data.neo4j.config.EnableNeo4jRepositories
import org.springframework.data.neo4j.config.Neo4jConfiguration
import org.springframework.web.servlet.config.annotation.EnableWebMvc

/**

 */
@Configuration
@EnableNeo4jRepositories(basePackages = "it.luis")
@ComponentScan("it.luis")
@EnableWebMvc
@EnableSwagger
class EngineConfiguration extends Neo4jConfiguration {


    EngineConfiguration() {
        setBasePackage("it.luis")
    }

    @Bean
    GraphDatabaseService graphDatabaseService() {
        return new GraphDatabaseFactory().newEmbeddedDatabase("neo4j.db");
    }
}