https://github.com/link-kou/plugin-configproperty
基于Spring,可以脱离容器使用配置获取,将配置以常理的方式改为注解注入的方式。
https://github.com/link-kou/plugin-configproperty
Last synced: 3 months ago
JSON representation
基于Spring,可以脱离容器使用配置获取,将配置以常理的方式改为注解注入的方式。
- Host: GitHub
- URL: https://github.com/link-kou/plugin-configproperty
- Owner: Link-Kou
- Created: 2020-03-19T00:34:55.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-12T01:25:10.000Z (almost 5 years ago)
- Last Synced: 2025-01-22T00:31:50.897Z (5 months ago)
- Language: Java
- Homepage:
- Size: 28.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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文件
```