Grails中的動態修改數據庫配置文件

          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中的動態修改數據庫配置文件 2015-08-02 22:54 希望的石頭

          很有用,謝謝分享。  回復  更多評論   

          公告


          導航

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

          統計

          常用鏈接

          留言簿(13)

          我參與的團隊

          隨筆分類(69)

          隨筆檔案(68)

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 南雄市| 武陟县| 赣州市| 盖州市| 奎屯市| 榆树市| 汕头市| 琼结县| 万全县| 广州市| 宁强县| 娱乐| 东乌| 绥德县| 刚察县| 深泽县| 黎城县| 称多县| 项城市| 托克托县| 刚察县| 东莞市| 呼伦贝尔市| 大化| 会昌县| 香港| 大渡口区| 中牟县| 秀山| 新沂市| 郑州市| 望谟县| 阜平县| 寿宁县| 资阳市| 祥云县| 贵州省| 建宁县| 木兰县| 湘潭县| 荆门市|