帮助Grails读取外部dataSource配置并加载适当的JDBC驱动程序

时间:2011-02-17 03:57:15

标签: tomcat grails config

在DataSource.groovy中定义(MySQL)dataSource时,我的Grails应用程序在Tomcat中运行良好。但是当使用外部配置文件时,我从Tomcat获取MySQL驱动程序的ClassNotFoundExceptions。也没有设置特殊的战争依赖关系。

我可能遗漏了一些明显的东西,但似乎无法识别它。尝试将MySQL连接器移动到CATALINA_HOME / lib,但是没有这样做。

非常感谢任何想法或帮助!

....     //加载外部配置
    def extConfig = System.properties.getProperty(“$ {appName} -config.location”);

    grails.config.locations = [“file:$ {extConfig} / $ {appName} -config.properties”]
    //配置文件内容     dataSource.pooled = true
    dataSource.dbCreate =“create-drop”
    dataSource.driverClassName =“com.mysql.jdbc.Driver”
    dataSource.username =“root”
    dataSource.password =“ttech”
    dataSource.url = “JDBC:MySQL的://本地主机:3306 /注册”

1 个答案:

答案 0 :(得分:1)

在我们的项目中,我们有一个用于配置的外部属性文件,我们也用它来设置数据源配置,在我们的例子中我们使用PostgresSQL,我们使用BuildConfig.groovy来包含驱动程序的jar文件,当生成WAR Grails依赖管理系统将jar放在WEB-INF / lib中,对我们来说效果很好,不需要放入Tomcat lib文件夹。

在您的设置中,我看到您没有指定数据源的方言,您可能也想在外部文件中检查它。

希望这有帮助!