`
qixin000
  • 浏览: 20887 次
  • 性别: Icon_minigender_1
  • 来自: 黑龙江
文章分类
社区版块
存档分类
最新评论

Grails的dataSource通过属性文件配置

阅读更多
//groovy代码,自动导入的类只有一个,所以按照idea的提示,不好用,两个都要加上。
import org.springframework.core.io.support.PropertiesLoaderUtils
import org.springframework.core.io.ClassPathResource  

def properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource("database.properties"))

dataSource {
    pooled = true
    dbCreate="update"
    url = properties.getProperty("url");
    driverClassName = "com.mysql.jdbc.Driver"
    dialect = org.hibernate.dialect.MySQL5Dialect
    username = properties.getProperty("username");
    password = properties.getProperty("password");
}


属性文件在相同文件夹,会被自动编译拷贝到classes文件夹中
url=jdbc:mysql://127.0.0.1:3308/vod?useUnicode=true&characterEncoding=gbk
username=root
password=金陵十三钗

0
0
分享到:
评论
1 楼 spe294096580 2012-06-09  
gggg

相关推荐

Global site tag (gtag.js) - Google Analytics