这是我的第一篇文章,所以要温柔! :)
我已经设置了一个grails项目(在grails上也相当新)并且我正在尝试将它连接到SQL 2008数据库,我已经将jtds-1.3.0.jar添加到lib文件夹和我的构建中路径,然后我将我的DataSource.groovy文件更改为如下所示: -
dataSource {
pooled = true
driverClassName = "net.sourceforge.jtds.jdbc.Driver"
dialect = "org.hibernate.dialect.SQLServerDialect"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
development {
dataSource {
dbCreate = "update"
url= "jdbc:jtds:sqlserver://TestServer:1433;databaseName=TestTable"
username = "test"
password = "test"
// logSql=true
}
}
麻烦的是,当我尝试编译时,我收到一个大量错误,内容如下,我错过了什么?我已经google了,但找不到明显的解决方案......:S
| Error 2013-03-08 12:44:33,451 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error executing bootstraps: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'net.sourceforge.jtds.jdbc.Driver'
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'net.sourceforge.jtds.jdbc.Driver'
答案 0 :(得分:15)
过去我遇到过类似的问题。
我已将JTDS的版本更改为1.2.6并且一切正常。
顺便说一句 - 您不需要手动添加jar。您只需将以下内容添加到BuildConfig.groovy
(在依赖项部分中):
runtime 'net.sourceforge.jtds:jtds:1.2.6'