gpt4 book ai didi

sql-server - 带有 MSSQL 服务器的 Grails

转载 作者:行者123 更新时间:2023-12-01 11:37:10 27 4
gpt4 key购买 nike

我尝试创建我的第一个 grails 应用程序,但是将我的应用程序连接到 MSSQL 服务器时出现了一些问题。

我的操作是(通过 Windows cmd):

  • 命令 grails create-app hello
  • 命令 cd hello
  • 之后我配置了数据源文件:
    dataSource {

    pooled = true
    jmxExport = true
    driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    username = "login"
    password = "password" }

    environments {

    development {
    dataSource {
    dbCreate = "update"
    url = "jdbc:jtds:sqlserver:\\<server-ip>;databaseName=Grails"
    }
    }
    test {
    dataSource {
    dbCreate = "update"
    url = "jdbc:jtds:sqlserver:\\<server-ip>;databaseName=Grails"
    }
    }
    production {
    dataSource {
    dbCreate = "update"
    url = "jdbc:jtds:sqlserver:\\<server-ip>;databaseName=Grails"

    }
    }
    }

    已经在 SQL Server 中创建了基本的“Grails”。
  • 命令 grails create-domain-class Hi
    然后我配置了域类 Hi.groovy
    class Hi { 
    String word
    int num
    static constraints = {
    }
    }
  • 最后我通过命令 grails run-app 运行了我的应用程序

  • 我认为在我的 Grails 基础中应该创建带有两个字段的新表 Hi,但是我收到这样的堆栈跟踪错误:
        | Configuring classpath
    ёхэ 01, 2014 2:54:33 PM java.util.prefs.WindowsPreferences <init>
    WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0
    | Running Grails application
    Error |
    2014-09-01 14:54:50,750 [localhost-startStop-1] ERROR pool.ConnectionPool - Una
    ble to create initial connections of pool.
    Message: com.microsoft.sqlserver.jdbc.SQLServerDriver
    Line | Method
    ->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 166 | run in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run . . . in java.lang.Thread
    Caused by ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    ->> 366 | run in java.net.URLClassLoader$1
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 355 | run in ''
    | 354 | findClass in java.net.URLClassLoader
    | 423 | loadClass in java.lang.ClassLoader
    | 266 | forName . in java.lang.Class
    | 334 | innerRun in java.util.concurrent.FutureTask$Sync
    | 166 | run . . . in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run in java.lang.Thread
    Error |
    2014-09-01 14:54:50,798 [localhost-startStop-1] ERROR pool.ConnectionPool - Una
    ble to create initial connections of pool.
    Message: com.microsoft.sqlserver.jdbc.SQLServerDriver
    Line | Method
    ->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 166 | run in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run . . . in java.lang.Thread
    Caused by ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    ->> 366 | run in java.net.URLClassLoader$1
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 355 | run in ''
    | 354 | findClass in java.net.URLClassLoader
    | 423 | loadClass in java.lang.ClassLoader
    | 266 | forName . in java.lang.Class
    | 334 | innerRun in java.util.concurrent.FutureTask$Sync
    | 166 | run . . . in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run in java.lang.Thread
    Error |
    2014-09-01 14:54:50,841 [localhost-startStop-1] ERROR pool.ConnectionPool - Una
    ble to create initial connections of pool.
    Message: com.microsoft.sqlserver.jdbc.SQLServerDriver
    Line | Method
    ->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 166 | run in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run . . . in java.lang.Thread
    Caused by ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    ->> 366 | run in java.net.URLClassLoader$1
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 355 | run in ''
    | 354 | findClass in java.net.URLClassLoader
    | 423 | loadClass in java.lang.ClassLoader
    | 266 | forName . in java.lang.Class
    | 334 | innerRun in java.util.concurrent.FutureTask$Sync
    | 166 | run . . . in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run in java.lang.Thread
    Error |
    2014-09-01 14:54:50,860 [localhost-startStop-1] ERROR context.GrailsContextLoade
    rListener - Error initializing the application: Error creating bean with name '
    transactionManagerPostProcessor': Initialization of bean failed; nested exceptio
    n is org.springframework.beans.factory.BeanCreationException: Error creating bea
    n with name 'transactionManager': Cannot resolve reference to bean 'sessionFacto
    ry' while setting bean property 'sessionFactory'; nested exception is org.spring
    framework.beans.factory.BeanCreationException: Error creating bean with name 'se
    ssionFactory': Cannot resolve reference to bean 'hibernateProperties' while sett
    ing bean property 'hibernateProperties'; nested exception is org.springframework
    .beans.factory.BeanCreationException: Error creating bean with name 'hibernatePr
    operties': Cannot resolve reference to bean 'dialectDetector' while setting bean
    property 'properties' with key [hibernate.dialect]; nested exception is org.spr
    ingframework.beans.factory.BeanCreationException: Error creating bean with name
    'dialectDetector': Invocation of init method failed; nested exception is org.spr
    ingframework.jdbc.support.MetaDataAccessException: Error while extracting Databa
    seMetaData; nested exception is java.sql.SQLException: com.microsoft.sqlserver.j
    dbc.SQLServerDriver
    Message: Error creating bean with name 'transactionManagerPostProcessor': Initia
    lization of bean failed; nested exception is org.springframework.beans.factory.B
    eanCreationException: Error creating bean with name 'transactionManager': Cannot
    resolve reference to bean 'sessionFactory' while setting bean property 'session
    Factory'; nested exception is org.springframework.beans.factory.BeanCreationExce
    ption: Error creating bean with name 'sessionFactory': Cannot resolve reference
    to bean 'hibernateProperties' while setting bean property 'hibernateProperties';
    nested exception is org.springframework.beans.factory.BeanCreationException: Er
    ror creating bean with name 'hibernateProperties': Cannot resolve reference to b
    ean 'dialectDetector' while setting bean property 'properties' with key [hiberna
    te.dialect]; nested exception is org.springframework.beans.factory.BeanCreationE
    xception: Error creating bean with name 'dialectDetector': Invocation of init me
    thod failed; nested exception is org.springframework.jdbc.support.MetaDataAccess
    Exception: Error while extracting DatabaseMetaData; nested exception is java.sql
    .SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    Line | Method
    ->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 166 | run in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run . . . in java.lang.Thread
    Caused by BeanCreationException: Error creating bean with name 'transactionManag
    er': Cannot resolve reference to bean 'sessionFactory' while setting bean proper
    ty 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanC
    reationException: Error creating bean with name 'sessionFactory': Cannot resolve
    reference to bean 'hibernateProperties' while setting bean property 'hibernateP
    roperties'; nested exception is org.springframework.beans.factory.BeanCreationEx
    ception: Error creating bean with name 'hibernateProperties': Cannot resolve ref
    erence to bean 'dialectDetector' while setting bean property 'properties' with k
    ey [hibernate.dialect]; nested exception is org.springframework.beans.factory.Be
    anCreationException: Error creating bean with name 'dialectDetector': Invocation
    of init method failed; nested exception is org.springframework.jdbc.support.Met
    aDataAccessException: Error while extracting DatabaseMetaData; nested exception
    is java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    ->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 166 | run in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run . . . in java.lang.Thread
    Caused by BeanCreationException: Error creating bean with name 'sessionFactory':
    Cannot resolve reference to bean 'hibernateProperties' while setting bean prope
    rty 'hibernateProperties'; nested exception is org.springframework.beans.factory
    .BeanCreationException: Error creating bean with name 'hibernateProperties': Can
    not resolve reference to bean 'dialectDetector' while setting bean property 'pro
    perties' with key [hibernate.dialect]; nested exception is org.springframework.b
    eans.factory.BeanCreationException: Error creating bean with name 'dialectDetect
    or': Invocation of init method failed; nested exception is org.springframework.j
    dbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; ne
    sted exception is java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerD
    river
    ->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 166 | run in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run . . . in java.lang.Thread
    Caused by BeanCreationException: Error creating bean with name 'hibernatePropert
    ies': Cannot resolve reference to bean 'dialectDetector' while setting bean prop
    erty 'properties' with key [hibernate.dialect]; nested exception is org.springfr
    amework.beans.factory.BeanCreationException: Error creating bean with name 'dial
    ectDetector': Invocation of init method failed; nested exception is org.springfr
    amework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMet
    aData; nested exception is java.sql.SQLException: com.microsoft.sqlserver.jdbc.S
    QLServerDriver
    ->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 166 | run in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run . . . in java.lang.Thread
    Caused by BeanCreationException: Error creating bean with name 'dialectDetector'
    : Invocation of init method failed; nested exception is org.springframework.jdbc
    .support.MetaDataAccessException: Error while extracting DatabaseMetaData; neste
    d exception is java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriv
    er
    ->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 166 | run in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run . . . in java.lang.Thread
    Caused by MetaDataAccessException: Error while extracting DatabaseMetaData; nest
    ed exception is java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDri
    ver
    ->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 166 | run in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run . . . in java.lang.Thread
    Caused by SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    ->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 166 | run in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run . . . in java.lang.Thread
    Caused by ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    ->> 366 | run in java.net.URLClassLoader$1
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    | 355 | run in ''
    | 354 | findClass in java.net.URLClassLoader
    | 423 | loadClass in java.lang.ClassLoader
    | 266 | forName . in java.lang.Class
    | 334 | innerRun in java.util.concurrent.FutureTask$Sync
    | 166 | run . . . in java.util.concurrent.FutureTask
    | 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
    | 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
    ^ 722 | run in java.lang.Thread
    | Error Forked Grails VM exited with error

    我究竟做错了什么?

    最佳答案

    原因是无法加载JDBC驱动程序,如trace中所述:

    ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver



    我在 DataSource.groovy 中使用以下内容:
    driverClassName = "net.sourceforge.jtds.jdbc.Driver"
    dialect = "org.hibernate.dialect.SQLServerDialect"

    在 BuildConfig.groovy 中放置如下内容:
    dependencies {
    runtime 'net.sourceforge.jtds:jtds:1.3.0'
    }

    关于sql-server - 带有 MSSQL 服务器的 Grails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25604622/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com