properties-scanner

The project can easily read configuration files, read the configuration information to the entity class.

License

License

GroupId

GroupId

com.github.developframework
ArtifactId

ArtifactId

properties-scanner
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

properties-scanner
The project can easily read configuration files, read the configuration information to the entity class.
Project URL

Project URL

https://github.com/developframework/properties-scanner
Source Code Management

Source Code Management

https://github.com/developframework/properties-scanner

Download properties-scanner

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
org.projectlombok : lombok Optional jar 1.16.10
org.slf4j : slf4j-api jar 1.7.21

Project Modules

There are no modules declared in this project.

Properties-scanner

可以方便的读取配置文件,把配置信息读取到实体类。

注解解释

@ScanProperties 加在类上,用属性location标明读取的properties文件名,用属性prefix设定前缀。

@ScanProperty 可选注解,标注在字段上,可以用alias设定别名,ifMissingOfValue指定当配置不存在时的默认值。

范例:

test.properties

#configuration_a
configuration_a.param1=xxxxx
configuration_a.param2=

#configuration_b
configuration_b.param1=yyyyy
configuration_b.param2=200

ConfigurationA.java

import com.github.developframework.scanner.annotation.ScanProperties;
import com.github.developframework.scanner.annotation.ScanProperty;
import lombok.Data;

@Data
@ScanProperties(location = "test", prefix = "configuration_a")
public class ConfigurationA {

    private String param1;

    @ScanProperty(alias = "param2", ifMissingOfValue = "999")
    private int param2;
}

ConfigurationB.java

import com.github.developframework.scanner.annotation.ScanProperties;
import lombok.Data;

@Data
@ScanProperties(location = "test", prefix = "configuration_b")
public class ConfigurationB {

    private String param1;

    private int param2;
}

Main.java

import com.github.developframework.scanner.PropertiesBox;
import com.github.developframework.scanner.PropertiesScanner;

public class Main {

    public static void main(String[] args) {
        PropertiesScanner propertiesScanner = new PropertiesScanner();
        PropertiesBox box = propertiesScanner.scan(ConfigurationA.class, ConfigurationB.class);

        ConfigurationA configuration_a = box.get(ConfigurationA.class);
        ConfigurationB configuration_b = box.get(ConfigurationB.class);

        System.out.println(configuration_a.toString());
        System.out.println(configuration_b.toString());
    }
}

Versions

Version
1.0.0