An open API service indexing awesome lists of open source software.

https://github.com/link-kou/plugin-configproperty

基于Spring,可以脱离容器使用配置获取,将配置以常理的方式改为注解注入的方式。
https://github.com/link-kou/plugin-configproperty

Last synced: 3 months ago
JSON representation

基于Spring,可以脱离容器使用配置获取,将配置以常理的方式改为注解注入的方式。

Awesome Lists containing this project

README

        

# Plugin-ConfigProperty

### Plugin-ConfigProperty 能做什么?

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

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

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

- @ConfigValue注解注入

---
### 使用环境

JAVA1.8
Maven

### Maven仓库

```xml


com.github.link-kou
config-property
1.0.2

```

### 使用教程

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

```java

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 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);
}

}

```
2. 在Spring环境XML配置

```xml





classpath*:**/JsonResultMsgCode.properties
classpath*:config/properties/globalparam.properties
classpath*:config/properties/RedisKeyName.properties



utf-8



```

3. 非Spring环境中默认读取所有properties文件

```xml
读取项目内所有properties文件
```