1.在conf中定义datasource.properties,如下所示
driverClass=com.mysql.jdbc.Driver
username=root
password=root
url=jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf8
2. 修改DataSource.groovy,如下所示
import org.springframework.core.io.ClassPathResource
import org.springframework.core.io.support.PropertiesLoaderUtils
def properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource('datasource.properties'))
dataSource {
pooled = true
driverClassName = properties.getProperty("driverClass")
username = properties.getProperty("username")
password = properties.getProperty("password")
url = properties.getProperty("url")
// driverClassName = "org.hsqldb.jdbcDriver"
// username = "sa"
// password = ""
}
参考http://bloodwolf-china.javaeye.com/blog/266166