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 想飛就飛 閱讀(1384) 評論(1)  編輯  收藏 所屬分類: Groovy/Grails

          評論

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

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

          公告


          導航

          <2015年8月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          統(tǒng)計

          常用鏈接

          留言簿(13)

          我參與的團隊

          隨筆分類(69)

          隨筆檔案(68)

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 房山区| 汉沽区| 贵州省| 绥滨县| 大荔县| 彰武县| 章丘市| 盐源县| 康马县| 曲靖市| 武穴市| 阿鲁科尔沁旗| 南昌市| 牡丹江市| 冀州市| 高州市| 准格尔旗| 长寿区| 涟水县| 南川市| 乌鲁木齐市| 潍坊市| 黎平县| 吕梁市| 松溪县| 连州市| 砀山县| 兴山县| 榆林市| 班玛县| 辛集市| 玛纳斯县| 桦川县| 广德县| 肥城市| 高邮市| 浑源县| 伊宁市| 监利县| 德化县| 永靖县|