Plugin-ConfigProperty-1.0.3

ConfigPropertyPlugin

License

License

Categories

Categories

config Application Layer Libs Configuration
GroupId

GroupId

com.github.link-kou
ArtifactId

ArtifactId

config-property
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

Plugin-ConfigProperty-1.0.3
ConfigPropertyPlugin
Project URL

Project URL

https://github.com/Link-Kou/Plugin-ConfigProperty
Project Organization

Project Organization

Link-Kou
Source Code Management

Source Code Management

https://github.com/Link-Kou/Plugin-ConfigProperty

Download config-property

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.link-kou/config-property/ -->
<dependency>
    <groupId>com.github.link-kou</groupId>
    <artifactId>config-property</artifactId>
    <version>1.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.link-kou/config-property/
implementation 'com.github.link-kou:config-property:1.0.3'
// https://jarcasting.com/artifacts/com.github.link-kou/config-property/
implementation ("com.github.link-kou:config-property:1.0.3")
'com.github.link-kou:config-property:jar:1.0.3'
<dependency org="com.github.link-kou" name="config-property" rev="1.0.3">
  <artifact name="config-property" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.link-kou', module='config-property', version='1.0.3')
)
libraryDependencies += "com.github.link-kou" % "config-property" % "1.0.3"
[com.github.link-kou/config-property "1.0.3"]

Dependencies

compile (1)

Group / Artifact Type Version
org.springframework : spring-context-support Optional jar 4.3.7.RELEASE

test (1)

Group / Artifact Type Version
org.springframework : spring-test jar 4.3.7.RELEASE

system (1)

Group / Artifact Type Version
com.sun » tools Optional jar 1.8

Project Modules

There are no modules declared in this project.

Plugin-ConfigProperty

Plugin-ConfigProperty 能做什么?

Spring环境中@Value具备非常强大的功能。希望能在非加载容器内的类提供类似的功能

  • 基于Spring,读取Properties文件
  • 提供读取配置注入的单一功能

Java的编译时注解;继承AbstractProcessor进行代码构建 替换常量的方式的配置

  • @ConfigValue注解注入

使用环境

JAVA1.8
Maven

Maven仓库

<dependency>
  <groupId>com.github.link-kou</groupId>
  <artifactId>config-property</artifactId>
  <version>1.0.2</version>
</dependency>

使用教程

  1. @ConfigValue会实现构建,在Spring环境中也可以使用
public class TestDemo {

   //初始化获取到项目内所有properties文件,修改后重启即可生效
   @ConfigValue(value = @Value("${Globalparam.Paging.DEFAULT_ITEMS_PER_PAGE}"))
   private Integer DEFAULT_ITEMS_PER_PAGE = 10;

   //查询不到properties文件,默认使用赋值数据
   @ConfigValue(@Value("${Globalparam.Paging.DEFAULT_ITEMS_PER_PAGE_NONE}"))
   private transient Integer DEFAULT_ITEMS_PER_PAGE_NONE = 2;

   //不支持非包装类型
   @ConfigValue(@Value("${Globalparam.Paging.DEFAULT_PAGE}"))
   private transient double DEFAULT_PAGE;

   //Config 通过Spring方式获取
   @ConfigValue(value = @Value("${Globalparam.Paging.DEFAULT_ITEMS_PER_PAGE}"), defaultValue = "5")
   private transient Config<Integer> DEFAULT_ITEMS_PER_PAGE_Config;

   @Test
   public void test() {
       final Integer integer1 = DEFAULT_ITEMS_PER_PAGE;
       final Integer integer2 = DEFAULT_ITEMS_PER_PAGE_NONE;
       final double integer3 = DEFAULT_PAGE;
       final Integer integer4 = DEFAULT_ITEMS_PER_PAGE_Config.get();
       System.out.println(integer1);
       System.out.println(integer2);
       System.out.println(integer3);
       System.out.println(integer4);
   }

}
  1. 在Spring环境XML配置
    <!--配置读取-->
    <bean class="com.linkkou.configproperty.spring.ConfigMsgPropertyConfigurer">
        <property name="locations">
            <list>
                <value>classpath*:**/JsonResultMsgCode.properties</value>
                <value>classpath*:config/properties/globalparam.properties</value>
                <value>classpath*:config/properties/RedisKeyName.properties</value>
            </list>
        </property>
        <property name="fileEncoding">
            <value>utf-8</value>
        </property>
    </bean> 
            
  1. 非Spring环境中默认读取所有properties文件
   读取项目内所有properties文件

Versions

Version
1.0.3
1.0.2
1.0.1
1.0.0