我正在尝试将我的 Grails 应用程序连接到 Firebird 数据库。
我在用:
到目前为止,这就是我所做的:
runtime "org.firebirdsql.jdbc:jaybird:2.2.2"
到依赖项部分。 数据源部分:
dataSource {
pooled = false
driverClassName = "org.firebirdsql.jdbc.FBDriver"
dialect = "org.hibernate.dialect.FirebirdDialect"
username = "SYSDBA"
password = "masterkey"
}
hibernate 部分:
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.provider_class = 'org.firebirdsql.pool.FBSimpleDataSource'
}
(我在上面的部分也有
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory
和 cache.provider_class = 'com.opensymphony.oscache.hibernate.OSCacheProvider'
在不同的场合,但都没有任何区别。)在运行我的 Grails 应用程序时,启动失败并出现一个巨大的错误,归结为以下消息:
java.lang.IllegalStateException: Could not load JDBC driver class [org.firebirdsql.jdbc.FBDriver]
我已经在网络上进行了广泛的搜索,但在任何地方都找不到工作的 Grails/Firebird 配置示例。有一个修复程序涉及复制 minij2ee.jar,但这是针对不同的错误消息。另外,人们建议清空 .grails 文件夹——我试过这个,但无济于事。
有人可以请教,我怎样才能让 Grails 与 Firebird 一起工作?
这是整个异常(exception),尽管它似乎在启动过程中重复了几次:
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 662 | run . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory':
Cannot resolve reference to bean 'dataSource' while setting bean property 'data
Source'; nested exception is org.springframework.beans.factory.BeanCreationExcep
tion: Error creating bean with name 'dataSource': Cannot resolve reference to be
an 'dataSourceUnproxied' while setting constructor argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean wi
th name 'dataSourceUnproxied': Error setting property values; nested exception i
s org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessE
xceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException:
Property 'driverClassName' threw exception; nested exception is java.lang.Illega
lStateException: Could not load JDBC driver class [org.firebirdsql.jdbc.FBDriver
]
使用 --verbose 运行 --stacktrace:
| Error Error running script --stacktrace --verbose: Cannot invoke method findAl
l() on null object
java.lang.NullPointerException: Cannot invoke method findAll() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:7
7)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaC
lassSite.java:45)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSi
teArray.java:45)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.j
ava:32)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSi
teArray.java:45)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMeta
MethodSite.java:55)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCa
llSite.java:116)
at org.codehaus.groovy.grails.cli.ScriptNameResolver.resolvesTo(ScriptNa
meResolver.groovy:30)
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.getPotentialScripts
(GrailsScriptRunner.java:489)
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeScriptWithCa
ching(GrailsScriptRunner.java:429)
at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeScriptWithCa
ching(GrailsScriptRunner.java:416)
at org.codehaus.groovy.grails.cli.GrailsScriptRunner$executeScriptWithCa
ching.call(Unknown Source)
at org.codehaus.groovy.grails.cli.interactive.InteractiveMode.parseAndEx
ecute(InteractiveMode.groovy:280)
at org.codehaus.groovy.grails.cli.interactive.InteractiveMode$parseAndEx
ecute.callCurrent(Unknown Source)
at org.codehaus.groovy.grails.cli.interactive.InteractiveMode.run(Intera
ctiveMode.groovy:133)
at org.codehaus.groovy.grails.cli.interactive.InteractiveMode$run.call(U
nknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSi
teArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCa
llSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCa
llSite.java:112)
at RunApp$_run_closure7_closure11.doCall(RunApp:127)
at RunApp$_run_closure7_closure11.doCall(RunApp)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(Refl
ectiveInterceptor.java:1243)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:
90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1082)
at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1106)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:906)
at groovy.lang.Closure.call(Closure.java:412)
at groovy.lang.Closure.call(Closure.java:406)
at groovy.lang.Closure.run(Closure.java:490)
at java.lang.Thread.run(Thread.java:662)
| Error Error running script --stacktrace --verbose: Cannot invoke method findAl
l() on null object
这是我的
BuildConfig.groovy
中的存储库块文件:repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
grailsCentral()
mavenLocal()
mavenCentral()
// uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
mavenRepo "http://snapshots.repository.codehaus.org"
mavenRepo "http://repository.codehaus.org"
mavenRepo "http://download.java.net/maven/2/"
mavenRepo "http://repository.jboss.com/maven2/"
}
最佳答案
您可能缺少 Jaybird 的必需依赖项。您需要包含 connector-api-1.5.jar
(在 Jaybird 发行版的 lib
文件夹中)在类路径上。替代方法是使用 jaybird-full-2.2.2.jar
(其中包括 connector-api-1.5.jar
的类)。
编辑
出于某种好奇,我安装了 grails 并试了一下。我最初也遇到了类似的错误(使用 grails console
)并且堆栈跟踪显示我 java.lang.NoClassDefFoundError: javax/resource/ResourceException
.看起来 grails - 与文档相反 - 不检索传递依赖项(这是一个 wong,参见 EDIT 2)。
在我明确添加对 'javax.resource:connector-api:1.5'
的运行时依赖之后,例如:
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
// runtime 'mysql:mysql-connector-java:5.1.22'
runtime 'org.firebirdsql.jdbc:jaybird-jdk17:2.2.2',
'javax.resource:connector-api:1.5'
}
有了这个额外的依赖,它就起作用了。如
connector-api
通常由应用服务器提供,最好将此指定为 provided
相反(您可能需要检查您的实际部署环境)。如果您需要支持检索生成的 key (或者 Gorm 可能需要它),那么我建议您还添加
'org.antlr:antlr-runtime:3.4'
(作为 runtime
依赖项)。编辑 2
经过一些额外的测试,看起来首先将下载的 jaybird 库安装到
lib
中。 ,然后声明一个依赖项将使 ivy 创建对该本地库的依赖项,而不是从 maven 中检索它。从 lib 文件夹中删除 jaybird 库后 和 删除 org.firebirdsql.jdbc
文件夹从我的 Ivy 缓存它正确地从 Maven 下载,包括 connector-api
依赖性。
关于hibernate - 在 Grails 中使用 Firebird 数据库的步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15247443/