SuperDiamond在JAVA项目中的三种应用方法实践总结
1、直接读取如下:
@Test
public static void test_simple(){
PropertiesConfiguration config = new PropertiesConfiguration("127.0.0.1", 8283, "Soft-1.0", "development");
System.out.println(config.getString("jdbc.driver"));
System.out.println(config.getString("jdbc.password"));
System.out.println(config.getString("jdbc.username"));
System.out.println(config.getString("jdbc.url"));
}
2、 SuperDiamond配置参数注入spring配置文件,使用Spring来加载。
<!-- 通过Spring来加载SuperDiamond -->
<bean id="propertiesConfiguration" class="com.github.diamond.client.PropertiesConfigurationFactoryBean">
<constructor-arg index="0" value="127.0.0.1" />
<constructor-arg index="1" value="8283" />
<constructor-arg index="2" value="Soft-1.0" />
<constructor-arg index="3" value="development" />
</bean>
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="properties" ref="propertiesConfiguration" />
</bean>
<!-- 利用SuperDiamond里面的配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
3、 在Spring中配置SuperDiamond(无参数),然后通过RunTime参数来加载SuperDiamond配置。
<!-- 通过Spring来加载SuperDiamond -->
<!-- 在运行时动态加载,配置VM参数:
-Dsuperdiamond.projcode=Soft-1.0
-Dsuperdiamond.host=127.0.0.1
-Dsuperdiamond.port=8283
-Dsuperdiamond.profile=development
-->
<bean id="propertiesConfiguration" class="com.github.diamond.client.PropertiesConfigurationFactoryBean"/>
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="properties" ref="propertiesConfiguration" />
</bean>
<!-- 利用SuperDiamond里面的配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>