grails 连接Mysql

1 安装这篇文章配置的:

http://blog.csdn.net/carolzhang8406/article/details/7766281


然后直接运行一直报错:


        at groo2012-07-27 10:39:05,656 [main] ERROR context.GrailsContextLoader
 - Error executing bootstraps: Error creating bean with name 'messageSource': In
itialization of bean failed; nested exception is org.springframework.beans.facto
ry.BeanCreationException: Error creating bean with name 'transactionManager': Ca
nnot resolve reference to bean 'sessionFactory' while setting bean property 'ses
sionFactory'; nested exception is org.springframework.beans.factory.BeanCreation
Exception: Error creating bean with name 'sessionFactory': Cannot resolve refere
nce to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; neste
d exception is org.springframework.beans.factory.BeanCreationException: Error cr
eating bean with name 'lobHandlerDetector': Invocation of init method failed; ne
sted exception is org.springframework.jdbc.support.MetaDataAccessException: Erro
r while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp
.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'messageSource': Initialization of bean failed; nested exception is org.s
pringframework.beans.factory.BeanCreationException: Error creating bean with nam
e '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 'sessionFacto
ry': Cannot resolve reference to bean 'lobHandlerDetector' while setting bean pr
operty 'lobHandler'; nested exception is org.springframework.beans.factory.BeanC
reationException: Error creating bean with name 'lobHandlerDetector': Invocation

 of init method failed; nested exception is org.springframework.jdbc.support.Met


can not load com.mysql.jdbc.Driver

.............................

..........................

然后google ,baidu  试了很多方法,都不对,人都快崩溃了,无意中看到下面这篇文章,找到问题所在,原来我所参考的文章并不对,下载这个zip包之后需要解压,把mysql-connector-java-5.1.21-bin.jar 这个拷贝到lib下面。



1.先下载MySql的驱动, http://www.mysql.com/products/connector/j/

2.将MySql的Jar包放到项目的lib文件夹下

http://www.grsage.com/new/GrailsMysql.html



然后重新运行,搞定 。

dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    username = "root"
    password = "root"
    dialect = org.hibernate.dialect.MySQL5InnoDBDialect
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = true
    cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create" // one of 'create', 'create-drop','update'
            url = "jdbc:mysql://127.0.0.1/grails?useUnicode=true&characterEncoding=UTF-8"  //你所创建的DB的名称,至于前面写localhost 和127那种都行,如果不在一个机器上,替换为对应的机器名。
        }
        hibernate {
            show_sql = true
        }
    }
    test {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop','update'
             url = "jdbc:mysql://127.0.0.1/grails?useUnicode=true&characterEncoding=UTF-8"


        }
    }
    production {
        dataSource {
            dbCreate = "update"
             url = "jdbc:mysql://127.0.0.1/grails?useUnicode=true&characterEncoding=UTF-8"


        }
    }
}


你可能感兴趣的:(exception,bean,grails,reference,nested,initialization)