2017-03-31 11 views
0

私はこれを検索しましたが、私のために働いた答えはありませんでした。アプリケーションで複数のdataSourcesを使用しようとしていて、application.ymlファイルで同じデータソースを宣言しています。以下は私のapplication.ymlファイルです。私controller.groovyファイルでGrails 3.0.9 application.ymlで複数のデータソースを使用する際のエラー

application.yml

--- 
grails: 
    profile: web 
    codegen: 
     defaultPackage: testingwebsockets 
info: 
    app: 
     name: '@[email protected]' 
     version: '@[email protected]' 
     grailsVersion: '@[email protected]' 
spring: 
    groovy: 
     template: 
      check-template-location: false 

--- 
grails: 
    mime: 
     disable: 
      accept: 
       header: 
        userAgents: 
         - Gecko 
         - WebKit 
         - Presto 
         - Trident 
     types: 
      all: '*/*' 
      atom: application/atom+xml 
      css: text/css 
      csv: text/csv 
      form: application/x-www-form-urlencoded 
      html: 
       - text/html 
       - application/xhtml+xml 
      js: text/javascript 
      json: 
       - application/json 
       - text/json 
      multipartForm: multipart/form-data 
      pdf: application/pdf 
      rss: application/rss+xml 
      text: text/plain 
      hal: 
       - application/hal+json 
       - application/hal+xml 
      xml: 
       - text/xml 
       - application/xml 
    urlmapping: 
     cache: 
      maxsize: 1000 
    controllers: 
     defaultScope: singleton 
    converters: 
     encoding: UTF-8 
    views: 
     default: 
      codec: html 
     gsp: 
      encoding: UTF-8 
      htmlcodec: xml 
      codecs: 
       expression: html 
       scriptlets: html 
       taglib: none 
       staticparts: none 

    plugin: 
     springsecurity: 
      userLookup: 
       userDomainClassName: 'lnmsconfig.SecUser' 
     # LDAP config 
      providerNames: 'ldapAuthProvider' # specify this when you want to skip attempting to load from db and only use LDAP 
      ldap: 
       context: 
        managerDn: 'CN=netcool,CN=Users,DC=ad,DC=syniverse,DC=com' 
        managerPassword: 'xxx' 
        server: 'xxx' 
       search: 
        base: 'DC=ad,DC=syniverse,DC=com' 
        filter: 'sAMAccountName={0}' # for Active Directory you need this 
        searchSubtree: true 
       auth: 
        hideUserNotFoundExceptions: false 
       useRememberMe: false 
       authorities: 
        ignorePartialResultException: true # typically needed for Active Directory 
        retrieveGroupRoles: true 
        groupSearchBase: 'OU=Syniverse,DC=ad,DC=syniverse,DC=com' 
        groupSearchFilter: 'member={0}' 
--- 
hibernate: 
    jdbc: 
     use_get_generated_keys: true 
    cache: 
     queries: false 
     use_second_level_cache: true 
     use_query_cache: false 
     region.factory_class: 'org.hibernate.cache.ehcache.EhCacheRegionFactory' 

endpoints: 
    jmx: 
     unique-names: true 

dataSources: 
    dataSource: 
     pooled: true 
     jmxExport: true 
     driverClassName: org.h2.Driver 
     username: sa 
     password: 

    swift: 
     driverClassName: oracle.jdbc.driver.OracleDriver 
     username: username 
     password: password 
     dialect: org.hibernate.dialect.Oracle10gDialect 
     dbCreate: validate #// one of 'create', 'create-drop', 'update', 'validate', '' 
     url: jdbc:oracle:thin:@servername:1521/serviceName 
     properties: 
      maxActive: -1 
      minEvictableIdleTimeMillis: 1800000 
      timeBetweenEvictionRunsMillis: 1800000 
      numTestsPerEvictionRun: 3 
      testOnBorrow: true 
      testWhileIdle: true 
      testOnReturn: true 
      validationQuery: "SELECT 1 from dual" 

environments: 
    development: 
     dataSources: 
      dataSource: 
       dbCreate: update 
       url: jdbc:oracle:thin:@xx.xx.xx.xx:1521:serviceName 
       dialect: org.hibernate.dialect.Oracle10gDialect 
       driverClassName: oracle.jdbc.driver.OracleDriver 
       username: xxx 
       password: zzz 
       properties: 
        maxActive: -1 
        minEvictableIdleTimeMillis: 1800000 
        timeBetweenEvictionRunsMillis: 1800000 
        numTestsPerEvictionRun: 3 
        testOnBorrow: true 
        testWhileIdle: true 
        testOnReturn: true 
        validationQuery: "SELECT 1 from dual" 

      swift: 
       driverClassName: oracle.jdbc.driver.OracleDriver 
       username: report_ro 
       password: Read4rpt! 
       dialect: org.hibernate.dialect.Oracle10gDialect 
       dbCreate: validate #// one of 'create', 'create-drop', 'update', 'validate', '' 
       url: jdbc:oracle:thin:@serverName:1521/serviceName 
       properties: 
        maxActive: -1 
        minEvictableIdleTimeMillis: 1800000 
        timeBetweenEvictionRunsMillis: 1800000 
        numTestsPerEvictionRun: 3 
        testOnBorrow: true 
        testWhileIdle: true 
        testOnReturn: true 
        validationQuery: "SELECT 1 from dual" 
    test: 
     dataSource: 
      dbCreate: update 
      url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE 
    production: 
     dataSource: 
      dbCreate: update 
      url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE 
      properties: 
       jmxEnabled: true 
       initialSize: 5 
       maxActive: 50 
       minIdle: 5 
       maxIdle: 25 
       maxWait: 10000 
       maxAge: 600000 
       timeBetweenEvictionRunsMillis: 5000 
       minEvictableIdleTimeMillis: 60000 
       validationQuery: SELECT 1 
       validationQueryTimeout: 3 
       validationInterval: 15000 
       testOnBorrow: true 
       testWhileIdle: true 
       testOnReturn: false 
       jdbcInterceptors: ConnectionState 
       defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED 

私は次のことを宣言しました。

DataSource dataSource_swift 上記で私はアプリケーションを起動しようとすると以下のエラーが表示されます。私は、単一のデータソースを使用する場合

エラー

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.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'transactionManager_swift' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager_swift': Cannot resolve reference to bean 'sessionFactory_swift' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_swift': Invocation of init method failed; nested exception is java.lang.NullPointerException 
    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.RELEASE.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.RELEASE] 
    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.6.RELEASE.jar:1.2.6.RELEASE] 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:687) ~[spring-boot-1.2.6.RELEASE.jar:1.2.6.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) ~[spring-boot-1.2.6.RELEASE.jar:1.2.6.RELEASE] 
    at grails.boot.GrailsApp.run(GrailsApp.groovy:52) [grails-core-3.0.9.jar:3.0.9] 
    at grails.boot.GrailsApp.run(GrailsApp.groovy:330) [grails-core-3.0.9.jar:3.0.9] 
    at grails.boot.GrailsApp.run(GrailsApp.groovy:319) [grails-core-3.0.9.jar:3.0.9] 
    at grails.boot.GrailsApp$run.call(Unknown Source) [grails-core-3.0.9.jar:3.0.9] 
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) [groovy-2.4.5.jar:2.4.5] 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) [groovy-2.4.5.jar:2.4.5] 
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) [groovy-2.4.5.jar:2.4.5] 
    at testingwebsockets.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 'transactionManager_swift' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager_swift': Cannot resolve reference to bean 'sessionFactory_swift' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_swift': Invocation of init method failed; nested exception is java.lang.NullPointerException 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    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.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:140) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1139) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[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.grails.transaction.TransactionManagerPostProcessor.initialize(TransactionManagerPostProcessor.java:75) ~[grails-core-3.0.9.jar:3.0.9] 
    at org.grails.transaction.TransactionManagerPostProcessor.setBeanFactory(TransactionManagerPostProcessor.java:53) ~[grails-core-3.0.9.jar:3.0.9] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1593) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1561) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    ... 19 common frames omitted 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager_swift': Cannot resolve reference to bean 'sessionFactory_swift' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_swift': Invocation of init method failed; nested exception is java.lang.NullPointerException 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    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.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[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:194) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    ... 37 common frames omitted 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_swift': Invocation of init method failed; nested exception is java.lang.NullPointerException 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[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:194) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    ... 47 common frames omitted 
Caused by: java.lang.NullPointerException: null 
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:244) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final] 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final] 
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final] 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final] 
    at org.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration.buildSessionFactory(GrailsAnnotationConfiguration.java:407) ~[grails-datastore-gorm-hibernate4-4.0.7.RELEASE.jar:na] 
    at org.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.doBuildSessionFactory(ConfigurableLocalSessionFactoryBean.java:479) ~[grails-datastore-gorm-hibernate4-4.0.7.RELEASE.jar:na] 
    at org.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.buildSessionFactory(ConfigurableLocalSessionFactoryBean.java:473) ~[grails-datastore-gorm-hibernate4-4.0.7.RELEASE.jar:na] 
    at org.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.afterPropertiesSet(ConfigurableLocalSessionFactoryBean.java:387) ~[grails-datastore-gorm-hibernate4-4.0.7.RELEASE.jar:na] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE] 
    ... 54 common frames omitted 
Error | 
Failed to start server (Use --stacktrace to see the full trace) 

すべてが正常に動作します。誰でも私が間違っている場所を教えてください。

答えて

0

私の問題の解決策が見つかりました。これは答えへのリンクです。基本的には、データソースをapplication.groovyに定義する必要があります。 Grails 3.x multiple datasources しかし、私はまだapplication.ymlと同じ結果を生成することができませんでした

関連する問題