我需要运行一个针对MySql/Hibernate和MongoDB的Grails 3应用程序。(Had正在Grails2.5上运行,没有任何故障)。
我尝试了许多不同的组合,搜索和尝试相关的答案,但没有运气。
配置使用了最新的Mongodb插件文档。
使用Grails 3.1.10:
grailsVersion=3.1.10我从build.gradle中的以下细节开始:
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.8.2"
classpath "org.grails.plugins:hibernate4:5.0.10"
}
}
...
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate4"
compile "org.hibernate:hibernate-ehcache"
console "org.grails:grails-console"
profile "org.grails.profiles:web"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.8.2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
//databases
compile 'org.grails.plugins:mongodb:6.0.0.M2'
runtime 'mysql:mysql-connector-java:5.1.36'
...
}application.yml:
---
hibernate:
cache:
queries: false
use_second_level_cache: true
use_query_cache: false
region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
environments:
development:
dataSource:
dbCreate: update
url: jdbc:mysql://localhost:3306/dbname
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username : "xxx"
password : "yyy"
properties:
maxActive : 50
maxIdle: 25
minIdle: 5
...
grails:
mongodb:
host: "localhost"
port: 27017
username: "blah"
password: "blah"
databaseName: "foo"这给了我一个错误:
15:13:58.001 [QUIET] [system.out] ERROR org.springframework.boot.SpringApplication - Application startup failed
15:13:58.001 [QUIET] [system.out] java.lang.NoClassDefFoundError: org/grails/datastore/gorm/plugin/support/ConfigSupport
15:13:58.001 [QUIET] [system.out] at grails.plugins.mongodb.MongodbGrailsPlugin.doWithSpring(MongodbGrailsPlugin.groovy:42)MongoDB grails插件找不到ConfigSupport
ConfigSupport.prepareConfig(config, (ConfigurableApplicationContext) applicationContext)然后,我尝试在所有可能的顺序中添加以下插件:
//compile 'org.grails:grails-datastore-gorm-hibernate4:6.0.0.M2'
//compile 'org.grails:grails-datastore-core:4.0.0.M2'
//compile 'org.grails:grails-datastore-gorm-plugin-support:6.0.0.M2'
//compile 'org.springframework.data:spring-data-mongodb:1.9.2.RELEASE'
//compile 'org.mongodb:mongodb-driver:3.3.0'
//compile 'org.mongodb:mongo-java-driver:3.3.0'不走运。
我还将mongodb:节移到yml文件中的grails:节。同样的错误。
因此,问题是如何让MongoDB与MySql一起使用grails3运行。
发布于 2016-08-09 08:38:36
好吧愚蠢的我。我使用以下简单的依赖项设置解决了这个难题:
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate4"
compile "org.hibernate:hibernate-ehcache"
console "org.grails:grails-console"
profile "org.grails.profiles:web"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.8.2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
//databases
compile 'org.grails.plugins:mongodb'
runtime 'mysql:mysql-connector-java:5.1.36'
runtime 'com.googlecode.json-simple:json-simple:1.1'以下几行似乎起到了作用:
compile 'org.grails.plugins:mongodb'省略版本号。这一点应该在文档中解释得更好一些。通常情况下,定义版本是件好事,或者这是不是太过时了?:-)
很高兴它能起作用
发布于 2016-08-22 14:29:51
好的,我找到了以前正确的答案,用于引用mongodb插件,即
compile 'org.grails.plugins:mongodb'
但我想用一个简短的清单来总结,经过多次试验和错误之后,我有一个正确运行的混合解决方案( hibernate + mysql和mongodb)。
因此,为了具有混合的mysql/mongo grails3配置,您必须
compile 'org.grails.plugins:hibernate4' compile 'org.hibernate:hibernate-ehcache' runtime 'mysql:mysql-connector-java:5.1.38'static mapWith="mongo" (如葡萄-芒果中所述)ObjectId id,以及import org.bson.types.ObjectId。Application.groovy设置
grails {
mongodb {
host = "localhost"
port = 27017
username = mongouser
password= mongopasswd
databaseName = mongoDBname
}
}
environments {
development {
dataSource {
driverClassName = "com.mysql.jdbc.Driver"
username = ...
password = ...
dbCreate = "create"
url = "jdbc:mysql://127.0.0.1:3306/dbnameMysql"
}
}
} 就这样。享受MongoDB吧。
发布于 2016-08-09 08:59:51
除了显示已确认有效的配置之外,我不确定还能提供更多帮助。最近,我将一个2.4.4应用程序转换为3.1.8,当然,我使用的是Oracle,而不是mysql。
在build.gradle中,我只拥有:
dependencies {
classpath "org.grails.plugins:hibernate4:5.0.6"
...
}
dependencies {
compile "org.grails.plugins:mongodb:5.0.0.RC1"
...
}在application.yml中:
mongodb:
databaseName: 'myApp'
engine: mapping引擎:映射位对我来说至关重要,它恢复到前面的持久性引擎,如这里所描述的http://gorm.grails.org/latest/mongodb/manual/index.html
我的MongodbGrailsPlugin.groovy中的MongodbGrailsPlugin.groovy()闭包如下所示:
Closure doWithSpring() {
def initializer = new MongoDbDataStoreSpringInitializer(config, grailsApplication.getArtefacts(DomainClassArtefactHandler.TYPE).collect() { GrailsClass cls -> cls.clazz })
initializer.registerApplicationIfNotPresent = false
initializer.setSecondaryDatastore( manager.hasGrailsPlugin("hibernate") )
return initializer.getBeanDefinitions((BeanDefinitionRegistry)applicationContext)
}没有对ConfigSupport的引用,它可能已经在您的后期版本中添加(或者没有),或者缺少一个依赖项。
https://stackoverflow.com/questions/38830836
复制相似问题