2014-09-01 2 views
3

Я попытался создать мое первое приложение grails, но есть некоторые проблемы с подключением моего приложения к серверу MSSQL.Grails with MSSQL Server

Мои действия были (окнами CMD):

  1. командным grails create-app hello
  2. Команда cd hello
  3. После этого я настроил DATASOURCE файл:

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

    Base " 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 должен создать новую таблицу 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 

Что я делаю неправильно?

+0

Я уверен, что вы не уточнили, что водитель в BuildConfig.groovy – wwarlock

ответ

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 Чтобы создать начальные соединения пула. Сообщение: Ошибка сети IOException: Соединение отклонено: connect' – AlexandrM

+1

Включили ли вы соединения TCP на вашем SQL Server? См. Например: http://stackoverflow.com/questions/9138172/enable-tcp-ip-remote-connections-to-sql-server-express-already-installed-databas – pierrant

+0

Да. TCP-соединения на моем сервере enebled – AlexandrM