如何在Grails应用程序中修复org.springframework.beans.factory.BeanCreationException错误? [英] How do I fix the org.springframework.beans.factory.BeanCreationException error in my Grails application?

查看:75
本文介绍了如何在Grails应用程序中修复org.springframework.beans.factory.BeanCreationException错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试运行grails应用程序时,我收到了一个巨大的错误列表.在我将数据库从MySQL迁移到SQL Server之前,该应用程序运行良好.我使用了SQL Server迁移助手,并且在那里一切正常.我还将sqljdbc4.jar添加到lib目录中,并更新了DataSource.groovy以与SQL Server一起使用.我已经尝试解决这个问题几天了,非常感谢您的投入.我对Grails,数据库,服务器等还不熟悉,所以如果我没有适当地描述此错误,我深表歉意.

I am receiving a huge error list when tying to run a grails application. The application worked fine until I migrated the database from MySQL to SQL Server. I used the SQL Server Migration Assistant and everything worked fine there. I also added the sqljdbc4.jar to the lib directory and updated DataSource.groovy to work with SQL Server. I have been trying to solve this problem for days now and would really appreciate your input. I am fairly new to Grails, Databases, Servers, etc. so I apologize if I have not described this error appropriately.

谢谢您的帮助!

版本:Grails 1.3.9,JDK 1.7.0_21,NetBeans IDE 7.3.1和Microsoft SQL Server 2008

Versions: Grails 1.3.9, JDK 1.7.0_21, NetBeans IDE 7.3.1, and Microsoft SQL Server 2008

这是我在运行grails run-app命令时遇到的错误:

This is the error I get when running the grails run-app command:

     context.GrailsContextLoader Error executing bootstraps:

     Error creating bean with name 'messageSource': 
     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 'hibernateProperties' 
     while setting bean property 'hibernateProperties'; nested exception is 
     org.springframework.beans.factory.BeanCreationException: 

     Error creating bean with name 'hibernateProperties': 
     Cannot resolve reference to bean 'dialectDetector' 
     while setting bean property 'properties' with key [hibernate.dialect]; nested exception is 
     org.springframework.beans.factory.BeanCreationException: 

     Error creating bean with name 'dialectDetector': 
     Invocation of init method failed; nested exception is          
     org.springframework.jdbc.support.MetaDataAccessException: 

     Error while extracting DatabaseMetaData; nested exception is 
     org.apache.commons.dbcp.SQLNestedException: 

     Cannot create PoolableConnectionFactory (Login failed for user 'dev'.)
     org.springframework.beans.factory.BeanCreationException:

     Error creating bean with name 'messageSource': 
     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 'hibernateProperties' 
     while setting bean property 'hibernateProperties'; nested exception is 
     org.springframework.beans.factory.BeanCreationException: 

     Error creating bean with name 'hibernateProperties': 
     Cannot resolve reference to bean 'dialectDetector' 
     while setting bean property 'properties' with key [hibernate.dialect]; nested exception is          
     org.springframework.beans.factory.BeanCreationException: 

     Error creating bean with name 'dialectDetector': 
     Invocation of init method failed; nested exception is 
     org.springframework.jdbc.support.MetaDataAccessException:


     Error while extracting DatabaseMetaData; nested exception is 
     org.apache.commons.dbcp.SQLNestedException:

     Cannot create PoolableConnectionFactory (Login failed for user 'dev'.)
        at org.grails.tomcat.InlineExplodedTomcatServer.doStart(InlineExplodedTomcatServer.groovy:112)
        at org.grails.tomcat.InlineExplodedTomcatServer$doStart.callCurrent(Unknown Source)
        at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:97)
        at grails.web.container.EmbeddableServer$start.call(Unknown Source)
        at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
        at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
        at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280)
        at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
        at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
        at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
        at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116)
        at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
        at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
        at RunApp$_run_closure1.doCall(RunApp.groovy:33)
        at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
        at gant.Gant.withBuildListeners(Gant.groovy:427)
        at gant.Gant.this$2$withBuildListeners(Gant.groovy)
        at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
        at gant.Gant.dispatch(Gant.groovy:415)
        at gant.Gant.this$2$dispatch(Gant.groovy)
        at gant.Gant.invokeMethod(Gant.groovy)
        at gant.Gant.executeTargets(Gant.groovy:590)
        at gant.Gant.executeTargets(Gant.groovy:589)

    Caused by: 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 'hibernateProperties' 
    while setting bean property 'hibernateProperties'; nested exception is 
    org.springframework.beans.factory.BeanCreationException: 

    Error creating bean with name 'hibernateProperties': 
    Cannot resolve reference to bean 'dialectDetector' 
    while setting bean property 'properties' with key [hibernate.dialect]; nested exception is 
    org.springframework.beans.factory.BeanCreationException: 

    Error creating bean with name 'dialectDetector': 
    Invocation of init method failed; nested exception is 
    org.springframework.jdbc.support.MetaDataAccessException: 

    Error while extracting DatabaseMetaData; nested exception is 
    org.apache.commons.dbcp.SQLNestedException: 

    Cannot create PoolableConnectionFactory (Login failed for user 'dev'.)
        ... 25 more



    Caused by: org.springframework.beans.factory.BeanCreationException: 

    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:

    Error creating bean with name 'hibernateProperties': 
    Cannot resolve reference to bean 'dialectDetector' 
    while setting bean property 'properties' with key [hibernate.dialect]; nested 
    exception is org.springframework.beans.factory.BeanCreationException: 

    Error creating bean with name 'dialectDetector': 
    Invocation of init method failed; nested exception is 
    org.springframework.jdbc.support.MetaDataAccessException: 

    Error while extracting DatabaseMetaData; nested exception is         
    org.apache.commons.dbcp.SQLNestedException: 

    Cannot create PoolableConnectionFactory (Login failed for user 'dev'.)
        ... 25 more



    Caused by: org.springframework.beans.factory.BeanCreationException: 

    Error creating bean with name 'hibernateProperties': 
    Cannot resolve reference to bean 'dialectDetector' 
    while setting bean property 'properties' with key [hibernate.dialect]; nested exception is 
    org.springframework.beans.factory.BeanCreationException: 

    Error creating bean with name 'dialectDetector': 
    Invocation of init method failed; nested exception is 
    org.springframework.jdbc.support.MetaDataAccessException: 

    Error while extracting DatabaseMetaData; nested exception is         
    org.apache.commons.dbcp.SQLNestedException: 

    Cannot create PoolableConnectionFactory (Login failed for user 'dev'.)
        ... 25 more



    Caused by: org.springframework.beans.factory.BeanCreationException:

    Error creating bean with name 'dialectDetector': 
    Invocation of init method failed; nested exception is 
    org.springframework.jdbc.support.MetaDataAccessException:

    Error while extracting DatabaseMetaData; nested exception is 
    org.apache.commons.dbcp.SQLNestedException: 

    Cannot create PoolableConnectionFactory (Login failed for user 'dev'.)
        ... 25 more


    Caused by: org.springframework.jdbc.support.MetaDataAccessException: 

    Error while extracting DatabaseMetaData; 
    nested exception is org.apache.commons.dbcp.SQLNestedException: 

    Cannot create PoolableConnectionFactory (Login failed for user 'dev'.)
        ... 25 more


    Caused by: org.apache.commons.dbcp.SQLNestedException: 
    Cannot create PoolableConnectionFactory (Login failed for user 'dev'.)

        at  org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
        at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
        at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
        at com.sun.proxy.$Proxy10.getMetaData(Unknown Source)
        ... 25 more

    Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'dev'.

        at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
        at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
        at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2529)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1905)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1893)
        at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1045)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:817)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)
        at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
        at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
        at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
        at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
        at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
        ... 28 more

这是我的DataSource.groovy文件

Here is my DataSource.groovy file

    dataSource {
    pooled = true
    //driverClassName = "com.mysql.jdbc.Driver" (driver for mysql)
    driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver" 
    dialect = "org.hibernate.dialect.SQLServer2008Dialect" 
    username = "dev"
    password = "dev"
    properties {
        maxActive = 30
        maxIdle = 5
        validationQuery = "/* ping */"
        testWhileIdle = true
        timeBetweenEvictionRunsMillis = 10000
        minEvictableIdleTimeMillis = 120000
    }
}

hibernate {
    cache.use_second_level_cache=true
    cache.use_query_cache=false
    cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "update" // one of 'create', 'create-drop','update'
            //url = "jdbc:mysql://localhost/timesheet_development?autoReconnect=true"
            url = "jdbc:sqlserver://localhost:1433;instanceName=sqlexpress;databaseName=timesheet_development"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            //url = "jdbc:mysql://localhost/timesheet_test?autoReconnect=true"
            url = "jdbc:sqlserver://localhost:1433;instanceName=sqlexpress;databaseName=timesheet_test"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            //url = "jdbc:mysql://localhost/timesheet_production?autoReconnect=true"
            url = "jdbc:sqlserver://localhost:1433;instanceName=sqlexpress;databaseName=timesheet_update"
            username = "********"
            password = "********"           
        }
    }
}

推荐答案

整天解决这个问题并从评论中获得有价值的输入后,我找到了解决问题的方法.

After working all day on this problem and getting valued input from comments, I have found the solution to my problem.

1)开发人员不是SQL Server的有效用户,因此我在phpMyAdmin中以及数据库的安全文件夹中添加了它.在将用户dev添加到MySQL之后,我还重新迁移了数据库.

1) Dev was not a valid user for SQL Server so I added it in phpMyAdmin as well as the security folders for the database. I also re-migrated the database after adding user dev to MySQL.

2)需要从application.properties文件中注释掉plugins.searchable = 0.6.4,以解决堆栈跟踪错误.

2) plugins.searchable=0.6.4 needed be commented out from the application.properties file in order to fix the stack trace errors.

3)通过浏览数据库表并更正了不正确迁移的数据类型,解决了Grails运行时异常.所有二进制数据类型都必须更改为位类型. grails应用程序现在可以完美运行.希望这可以帮助其他人解决这个问题!

3) The Grails Runtime Exceptions were solved by going through the database tables and correcting the data types that were improperly migrated. All binary data types had to be changed to bit type. The grails app now runs flawlessly. Hope this helps anybody else out there with this problem!

这篇关于如何在Grails应用程序中修复org.springframework.beans.factory.BeanCreationException错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆