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=金陵十三钗

你可能感兴趣的:(dataSource,properties,grails)