1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-22 01:48:50 +00:00

feat: 添加注入配置允许Null的注解

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-08-24 22:29:42 +08:00
parent 33ef4ffe5a
commit 2968608c71
4 changed files with 28 additions and 4 deletions

View File

@ -14,6 +14,11 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface ConfigNode { public @interface ConfigNode {
/**
* @return 是否允许为空
*/
boolean notNull() default false;
/** /**
* Defines the path to the node if it has another as the variable name. * Defines the path to the node if it has another as the variable name.
* Every indention is separated with an dot ('.') * Every indention is separated with an dot ('.')

View File

@ -72,8 +72,8 @@ public abstract class InjectConfig extends AbstractInjectConfig {
} catch (final IllegalAccessException ex) { } catch (final IllegalAccessException ex) {
Log.log(Level.SEVERE, "自动注入配置错误!", ex); Log.log(Level.SEVERE, "自动注入配置错误!", ex);
} }
} else { } else if (field.getAnnotation(Nullable.class) == null) {
Log.debug("配置节点 {0} 丢失!", realPath); Log.warning(String.format("配置节点 %s 丢失!", realPath));
} }
} }
} }

View File

@ -53,8 +53,8 @@ public class InjectConfigurationSection extends AbstractInjectConfig {
} catch (final IllegalAccessException ex) { } catch (final IllegalAccessException ex) {
Log.log(Level.SEVERE, "自动注入配置错误!", ex); Log.log(Level.SEVERE, "自动注入配置错误!", ex);
} }
} else { } else if (field.getAnnotation(Nullable.class) == null) {
Log.debug("配置节点 {0} 丢失!", realPath); Log.warning(String.format("配置节点 %s 丢失!", realPath));
} }
} }
} }

View File

@ -0,0 +1,19 @@
package pw.yumc.YumCore.config;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 允许配置值为空
*
* @author
* @since 2016年8月24日 下午10:41:55
*/
@Target(ElementType.FIELD)
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface Nullable {
}