2015-10-14 85 views
2

Grails 3(3.0.9)應用程序無法在TC服務器上啓動,其中2個使用每個JNDI數據源的Grails 2應用程序運行正常。如何在Grails 3.x中配置JNDI數據源?

似乎在Grails 3中複製我的Grails 2 JNDI設置不起作用(我爲我的prod數據源設置保留了其他所有默認和指定的driverClassName,dbCreate和jndiName)。

該應用程序沒有問題直接通過JDBC連接到MySQL數據庫。只有JNDI使得它與下面的異常(片段)崩潰......

ERROR grails.boot.GrailsApp - Application startup failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.spr 
ingframework.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 'dat 
aSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot r 
esolve reference to bean 'dataSourceLazy' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with 
name 'dataSourceLazy': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreation 
Exception: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class 
name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) ~[spring-beans-4.1.7.RELEASE.jar:4 
.1.7.RELEASE] 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.7.RELEASE.jar:4.1 
.7.RELEASE] 
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE 
] 
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
     at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:199) ~[spring-context-4.1.7.RELEA 
SE.jar:4.1.7.RELEASE] 
     at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:615) ~[spring-context-4.1.7.RELEASE.jar:4.1.7.R 
ELEASE] 
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465) ~[spring-context-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE] 
     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) ~[spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE] 
     at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) ~[spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE] 
     at grails.boot.GrailsApp.run(GrailsApp.groovy:52) [grails-core-3.0.7.jar:3.0.7] 
     at grails.boot.GrailsApp.run(GrailsApp.groovy:330) [grails-core-3.0.7.jar:3.0.7] 
     at grails.boot.GrailsApp.run(GrailsApp.groovy:319) [grails-core-3.0.7.jar:3.0.7] 
     at grails.boot.GrailsApp$run.call(Unknown Source) [grails-core-3.0.7.jar:3.0.7] 
     at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) [groovy-2.4.4.jar:2.4.4] 
     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) [groovy-2.4.4.jar:2.4.4] 
     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) [groovy-2.4.4.jar:2.4.4] 
     at miron3.Application.main(Application.groovy:8) [main/:na] 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while sett 
ing bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve refe 
rence to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dat 
aSource': Cannot resolve reference to bean 'dataSourceLazy' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error c 
reating bean with name 'dataSourceLazy': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.fa 
ctory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need 
to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial 
     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEA 
SE] 
     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[spring-beans-4.1.7.RELEASE.jar:4.1. 
7.RELEASE] 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1477) ~[spring-beans-4.1.7.RELEA 
SE.jar:4.1.7.RELEASE] 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-4.1.7.RELEASE.jar: 
+0

嗨@Edo你已經有東西了嗎?我試圖與jndi連接:( – akiong

+1

嗨,我實際上得到了來自grails團隊的迴應,他們告訴我,功能已停止在grails 3,除非有非常大的需求,我只是切換到非jndi datasurces。 – Edo

+0

哦,我明白了,所以在grails 3中,我們不能再使用jndi了嗎? 感謝你對這個信息的... – akiong

回答

0

application.yml我更換網址該值,它爲我工作。你可以嘗試一樣的。

production: 
     dataSource: 
      dbCreate: update    
      jndiName: java:comp/env/jdbc/dbjndiname 
+1

不是,那是以前在2.x中工作的,但現在不再是這樣了 – Edo

1

你上面的正確無效。我遵循以下步驟,現在爲我工作。這樣定義

  1. Tomcat的context.xml文件:

    Resource name="grailsDB" 
    
  2. application.yml加入該生產數據源。

    production: 
        dataSource: 
         dbCreate: update 
         jndiName: java:comp/env/grailsDB 
    
  3. 創建的grails-app/conf目錄/ DataSource.groovy文件中,基於https://grails.github.io/grails-doc/3.0.x/ref/Plug-ins/dataSource.html文件。

    dataSource { 
        jndiName = "java:comp/env/grailsDB" 
    } 
    
  4. 使用grails war命令創建了戰爭文件。

  5. 部署在tomcat中,並通過添加刪除樣本數據進行測試。

    這是我測試過的軟件版本。

 
APPLICATION STATUS 
    Environment: production 
    App profile: web 
    App version: 0.1 
    Grails version: 3.0.3 
    Groovy version: 2.4.3 
    JVM version: 1.8.0_65 

希望這有助於。

謝謝 -SR

+0

這是否適用於多個數據源? –

相關問題