关闭

Apache Commons-configuration 范例

2260人阅读 评论(0) 收藏 举报
configuration.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    
<header>
        
<result forceReloadCheck="true"></result>
    
</header>

    
<override>
        
<system />
        
<properties fileName="${user.home}/users.properties">
            
<reloadingStrategy config-class="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy"
                refreshDelay
="1000" />
        
</properties>
        
<xml fileName="hibernate.cfg.xml" />
    
</override>
</configuration>

users.properties
a.b=sss
a.a=${sys:user.dir}-${a.b}


hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
>

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

    
<session-factory>
        
<property name="connection.username">aName</property>
        
<property name="connection.url">
            jdbc:oracle:thin:@192.168.0.123:1521:ora123
        
</property>
        
<property name="dialect">
            org.hibernate.dialect.Oracle9Dialect
        
</property>
        
<property name="myeclipse.connection.profile">
            oracle.jdbc.driver.OracleDriver
        
</property>
        
<property name="connection.password">pass</property>
        
<property name="connection.driver_class">
            oracle.jdbc.driver.OracleDriver
        
</property>
        
<mapping resource="test/TABLE_ONE.hbm.xml" />

    
</session-factory>

</hibernate-configuration>


Test.java
    ConfigurationBuilder factory = new DefaultConfigurationBuilder("bin/configuration.xml");
    Configuration config 
= factory.getConfiguration();
    System.out.println(config.getClass());
   
    
for (int i = 0; i < 50; i++{
        
//System.out.println(rs.reloadingRequired());
        System.out.println(config.getString("a.a"));
        Thread.sleep(
1000);
    }

        System.out.println(config.getString("a.a"));
        System.out.println(config.getString("a.b"));
        System.out.println(config.getString("session-factory.mapping[@resource]"));
        System.out.println(config.getString("session-factory.property(0)[@name]"));
        System.out.println(config.getString("session-factory.property(1)"));
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:262120次
    • 积分:3463
    • 等级:
    • 排名:第9628名
    • 原创:78篇
    • 转载:20篇
    • 译文:0篇
    • 评论:59条
    最新评论