2014-09-01 43 views
3

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

我的行为是(通过在cmd窗口):

  1. 命令grails create-app hello
  2. 命令cd hello
  3. 之后,我配置的数据源文件:

    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" 
    
        } 
    } 
    } 
    

    基地“ Grails“是一个lredy在SQL Server中创建。

  4. 命令grails create-domain-class Hi

    然后我配置的域类Hi.groovy

    class Hi { 
        String word 
        int num 
        static constraints = { 
        } 
    } 
    
  5. 最后我被命令跑到我的应用程序grails run-app

我认为,在我的Grails基础上e应该创建新表嗨有两个字段,但我得到这样的stacktrace错误:

| 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 

我做错了什么?

+0

我敢肯定你不是指定驾驶员在BuildConfig.groovy – wwarlock 2014-09-01 11:54:42

回答

5

的原因是JDBC驱动程序无法加载,所报道的痕迹:

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' 
} 
+0

这有助于与ClassNotFoundExeption来解决问题,但我有这样的错误,但: '错误| 2014-09-01 16:42:23,510 [localhost-startStop-1] ERROR pool.ConnectionPool - Una ble创建池的初始连接。 消息:网络错误IOException:连接被拒绝:连接' – AlexandrM 2014-09-01 13:01:58

+1

您在SQL Server中启用了TCP连接吗?看例如:http://stackoverflow.com/questions/9138172/enable-tcp-ip-remote-connections-to-sql-server-express-already-installed-databas – pierrant 2014-09-01 13:06:36

+0

是的。我的服务器中的TCP连接是可编辑的 – AlexandrM 2014-09-01 13:37:32