【问题标题】:Exception in grails dbm-update - NoSuchBeanDefinitionExceptiongrails dbm-update 中的异常 - NoSuchBeanDefinitionException
【发布时间】:2014-10-17 15:56:55
【问题描述】:

当我运行"grails dbm-update --dataSource=production" 时,出现以下异常:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory_production' is defined
    at grails.plugin.databasemigration.MigrationUtils.findSessionFactory(MigrationUtils.groovy:142)
    at grails.plugin.databasemigration.MigrationUtils.getDatabase(MigrationUtils.groovy:105)
    at _DatabaseMigrationCommon_groovy$_run_closure2_closure11.doCall(_DatabaseMigrationCommon_groovy:52)
    at grails.plugin.databasemigration.MigrationUtils.executeInSession(MigrationUtils.groovy:133)
    at _DatabaseMigrationCommon_groovy$_run_closure2.doCall(_DatabaseMigrationCommon_groovy:51)
    at DbmUpdate$_run_closure1.doCall(DbmUpdate:25)

它适用于默认数据源(如果我运行“grails dbm-update”),但不适用于生产或我的自定义数据源。

我使用 Grails 2.4.3 和 database-migration:1.4.0。 我在 Amazon AWS - RDS MySql DB 上运行它。

这是我的数据源:

production {        
   grails.dbconsole.enabled = true      
   dataSource {             
      grails.dbconsole.enabled = true           
      username = "myusername"           
      password = "mypassword"           
      pooled = true             
      dbCreate = "none"             
      driverClassName = "com.mysql.jdbc.Driver"             
      url = "jdbc:mysql://mydatabase.us-west-1.rds.amazonaws.com:3306/ebdb?autoReconnect=true"          dialect = org.hibernate.dialect.MySQL5InnoDBDialect             
      properties {
         validationQuery = "SELECT 1"
         testOnBorrow = true
         testOnReturn = true
         testWhileIdle = true
         timeBetweenEvictionRunsMillis = 1800000
         numTestsPerEvictionRun = 3
         minEvictableIdleTimeMillis = 1800000
      }          
   }
}

【问题讨论】:

  • 我曾经在 Windows 上的不同控制台(cmd 或 powershell)上遇到过奇怪的问题。它只适用于 cmd。但您也可以使用DBM Docu 中的通知。在那里你必须引用参数
  • 可能只是复制粘贴错误,但是方言真的和url在同一行吗?

标签: grails groovy data-migration


【解决方案1】:

您称为production 的项目不是数据源,而是production 环境中常规数据源的配置。所以这个调用应该有效:

grails prod dbm-update

【讨论】:

  • 自定义环境呢?我必须使用“grails -Dgrails.env=mycustomenv dbm-update”?
  • @user2153912 我不能根据经验说话,但我认为这是可行的,因为 env 很早就被处理了,而 dev/test/prod 只是最常见情况的一些捷径。所以它适用于产品,但不适用于您的环境?错误?
  • 是的,它也适用于自定义环境。谢谢。
猜你喜欢
  • 1970-01-01
  • 2015-10-08
  • 1970-01-01
  • 1970-01-01
  • 2012-03-19
  • 2014-10-28
  • 2013-09-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多