Grails中的動態(tài)修改數(shù)據(jù)庫配置文件

          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

          posted on 2010-08-12 14:30 想飛就飛 閱讀(1396) 評論(1)  編輯  收藏 所屬分類: Groovy/Grails

          評論

          # re: Grails中的動態(tài)修改數(shù)據(jù)庫配置文件 2015-08-02 22:54 希望的石頭

          很有用,謝謝分享。  回復(fù)  更多評論   

          公告


          導(dǎo)航

          <2010年8月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          統(tǒng)計(jì)

          常用鏈接

          留言簿(13)

          我參與的團(tuán)隊(duì)

          隨筆分類(69)

          隨筆檔案(68)

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 宣恩县| 乐陵市| 平湖市| 尉犁县| 陇西县| 肥城市| 潞西市| 洪洞县| 淄博市| 安陆市| 阿克| 大安市| 海门市| 永新县| 南召县| 安徽省| 余姚市| 汕尾市| 阳江市| 乾安县| 济南市| 喀喇沁旗| 霍林郭勒市| 郯城县| 宁津县| 门头沟区| 大名县| 恩平市| 鄂尔多斯市| 顺义区| 增城市| 阿巴嘎旗| 秦安县| 龙海市| 蕲春县| 山丹县| 大庆市| 星子县| 双峰县| 西充县| 西昌市|