Browse Source

配置文件读写工具类

remotes/1611766341912730171/master
richie 5 years ago
parent
commit
419b8ef2f9
  1. 12
      src/main/java/com/fanruan/api/conf/BaseConfiguration.java
  2. 12
      src/main/java/com/fanruan/api/conf/BaseUniqueKey.java
  3. 21
      src/main/java/com/fanruan/api/conf/ConfigContextKit.java
  4. 10
      src/main/java/com/fanruan/api/security/SecurityKit.java
  5. 44
      src/test/java/com/fanruan/api/conf/BaseConfigurationTest.java

12
src/main/java/com/fanruan/api/conf/BaseConfiguration.java

@ -0,0 +1,12 @@
package com.fanruan.api.conf;
import com.fr.config.DefaultConfiguration;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-16
*/
public abstract class BaseConfiguration extends DefaultConfiguration {
}

12
src/main/java/com/fanruan/api/conf/BaseUniqueKey.java

@ -0,0 +1,12 @@
package com.fanruan.api.conf;
import com.fr.config.utils.UniqueKey;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-16
* 需要存入fine_conf_entity配置库中的属性对象需要继承此抽象类
*/
public abstract class BaseUniqueKey extends UniqueKey {
}

21
src/main/java/com/fanruan/api/conf/ConfigContextKit.java

@ -0,0 +1,21 @@
package com.fanruan.api.conf;
import com.fr.config.ConfigContext;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-16
*/
public class ConfigContextKit {
/**
* 从配置对象池中创建或者获取配置对象实例
* @param clazz 配置实例类型
* @param <T> 类型
* @return 配置对象
*/
public static <T extends BaseConfiguration> T getConfigInstance(final Class<T> clazz) {
return ConfigContext.getConfigInstance(clazz);
}
}

10
src/main/java/com/fanruan/api/security/SecurityKit.java

@ -0,0 +1,10 @@
package com.fanruan.api.security;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-16
* 文本加密解密相关的工具类
*/
public class SecurityKit {
}

44
src/test/java/com/fanruan/api/conf/BaseConfigurationTest.java

@ -0,0 +1,44 @@
package com.fanruan.api.conf;
import com.fanruan.api.Prepare;
import com.fr.config.holder.Conf;
import org.junit.Assert;
import org.junit.Test;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-16
*/
public class BaseConfigurationTest extends Prepare {
@Test
public void testGet() {
MyConf conf = MyConf.getInstance();
Assert.assertEquals(10, conf.getCount());
conf.setCount(100);
Assert.assertEquals(100, conf.getCount());
}
private static class MyConf extends BaseConfiguration {
private static volatile MyConf instance = null;
public static MyConf getInstance() {
if (instance == null) {
instance = ConfigContextKit.getConfigInstance(MyConf.class);
}
return instance;
}
private Conf<Integer> count = HolderKit.simple(10);
public int getCount() {
return count.get();
}
public void setCount(int count) {
this.count.set(count);
}
}
}
Loading…
Cancel
Save