2014-02-06 163 views
0

我有在DataSource.groovy中的定义为数据源的Grails应用程序:Grails的JNDI数据源不工作

dataSource { 
    pooled = true 
    driverClassName = "oracle.jdbc.OracleDriver" 
    username = "myusername" 
    password = "mypassword" 
} 
hibernate { 
    cache.use_second_level_cache = true 
    cache.use_query_cache = false 
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' 
} 
// environment specific settings 
environments { 
    development { 
     dataSource { 
      dbCreate = "validate" 
      url = "jdbc:oracle:thin:@server:1521:instance" 
     logSql = true 
     } 

    } 
} 

这一切工作正常,但我想用一个JNDI数据源。

Config.groovy中我有:

grails.naming.entries = [ 
'jdbc/pms_dev': [ 
    type: 'java.sql.DataSource', 
    auth: 'Container', 
    description: 'Main datasource', 

    url: 'jdbc:oracle:thin:@server:1521:instance', 
    username: "myusername", 
    password: "mypassword", 
    driverClassName: "oracle.jdbc.OracleDriver", 
    maxActive: "8", 
    maxIdle: "4" 
    ] 
] 

我改变DataSource.groovy中的发展部分:

development { 
    dataSource { 
     dbCreate = "validate" 
     jndiName = "java:comp/env/jdbc/pms_dev" 
     logSql = true 
    } 
} 

现在做的Grails runApp时,我得到了以下错误:

| Error 2014-02-06 11:25:58,402 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
    Line | Method 
->> 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 '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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
->> 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 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
->> 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 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
->> 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 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
->> 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 NamingException: Cannot create resource instance 
->> 146 | getObjectInstance in org.apache.naming.factory.ResourceFactory 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 304 | getObjectInstance in javax.naming.spi.NamingManager 
| 843 | lookup . in org.apache.naming.NamingContext 
| 154 | lookup in  '' 
| 831 | lookup . in  '' 
| 154 | lookup in  '' 
| 831 | lookup . in  '' 
| 154 | lookup in  '' 
| 831 | lookup . in  '' 
| 168 | lookup in  '' 
| 158 | lookup . in org.apache.naming.SelectorContext 
| 392 | lookup in javax.naming.InitialContext 
| 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 
| Error 2014-02-06 11:25:58,574 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing Grails: 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
    Line | Method 
->> 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 '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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
->> 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 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
->> 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 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
->> 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 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
->> 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 NamingException: Cannot create resource instance 
->> 146 | getObjectInstance in org.apache.naming.factory.ResourceFactory 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 304 | getObjectInstance in javax.naming.spi.NamingManager 
| 843 | lookup . in org.apache.naming.NamingContext 
| 154 | lookup in  '' 
| 831 | lookup . in  '' 
| 154 | lookup in  '' 
| 831 | lookup . in  '' 
| 154 | lookup in  '' 
| 831 | lookup . in  '' 
| 168 | lookup in  '' 
| 158 | lookup . in org.apache.naming.SelectorContext 
| 392 | lookup in javax.naming.InitialContext 
| 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 
| Error 2014-02-06 11:25:58,887 [localhost-startStop-1] ERROR [localhost].[/osrpms] - Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener 
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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
    Line | Method 
->> 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 '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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
->> 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 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
->> 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 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
->> 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 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NamingException: Cannot create resource instance 
->> 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 NamingException: Cannot create resource instance 
->> 146 | getObjectInstance in org.apache.naming.factory.ResourceFactory 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 304 | getObjectInstance in javax.naming.spi.NamingManager 
| 843 | lookup . in org.apache.naming.NamingContext 
| 154 | lookup in  '' 
| 831 | lookup . in  '' 
| 154 | lookup in  '' 
| 831 | lookup . in  '' 
| 154 | lookup in  '' 
| 831 | lookup . in  '' 
| 168 | lookup in  '' 
| 158 | lookup . in org.apache.naming.SelectorContext 
| 392 | lookup in javax.naming.InitialContext 
| 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 
| Error 2014-02-06 11:25:59,184 [localhost-startStop-1] ERROR core.StandardContext - Error listenerStart 
| Error 2014-02-06 11:25:59,184 [localhost-startStop-1] ERROR core.StandardContext - Context [/osrpms] startup failed due to previous errors 
+0

我有同样的问题。刚刚创建了一个带有一个域类和一行scafolded控制器的最基本项目,并得到相同的错误。 2.4.4和oracle java 1.7以及最新的intelij的新安装13.1 ide –

回答

0

这似乎是你的grails数据源设置不能访问那个JNDI数据源的一些方式......我不要以为你错过了语法或其他东西,但我想你需要检查服务器可以访问使用的URL和它是应用程序和运行....

@server其中是定义?应该是一个IP地址...

任何帮助,您可以检查:

检查这个[1] JNDI datasource to oracle with grails 1.3

和Grails文档[2] http://grails.org/doc/2.0.0.M2/guide/conf.html

+0

服务器和实例不是真正的值。但是,如果用于服务器的实际价值是Oracle数据库服务器的域名,并且它解析为一个IP地址。服务器启动了,因为如果我使用数据源中的url而不是JNDI,所有这些都按预期工作。感谢您的文档链接。 –

0

问题的Config.groovy

java.sql.DataSource应该是javax.sql.DataSource