First, directly through the propertiesconfiguration to read value according to key.
Second, the Superdiamond configuration parameters are injected into the spring configuration file, using spring to load.
Third, configure Superdiamond (no parameters) in spring, and then load the Superdiamond configuration through the runtime parameters.
1, directly read as follows:
@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 configuration parameters are injected into the spring configuration file and loaded using spring.
<!--load Superdiamond through spring-- ><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> <!-- Take advantage of Superdiamond configuration--<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. Configure Superdiamond (no parameters) in spring and then load the Superdiamond configuration through the runtime parameters.
<!--load Superdiamond through spring
<!--dynamically load at run time, configure VM parameters:
-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><!--Take advantage of Superdiamond configuration--><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>
Summary of three application methods of Superdiamond in Java project