asgc-configure

this is a java config load util.

License

License

Categories

Categories

config Application Layer Libs Configuration
GroupId

GroupId

com.github.aoshiguchen.framework
ArtifactId

ArtifactId

asgc-configure
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

asgc-configure
this is a java config load util.
Project URL

Project URL

https://github.com/aoshiguchen/asgc-configure
Source Code Management

Source Code Management

https://github.com/aoshiguchen/asgc-configure

Download asgc-configure

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
log4j : log4j jar 1.2.17

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

asgc-configure

asgc-configure是傲世孤尘开源的一个配置管理器。特点概述:

  • 使用简单 :一行代码读取配置,支持注解,很方便集成到spring容器中。
  • 例程丰富 :对于本工具的使用提供了详细的示例程序。

如何使用asgc-configure

1、配置工厂读取 (ConfigReaderFactory)

配置文件(config.properties)内容如下: projectName=asgc-configure

jdbc.host=118.89.63.66 jdbc.port=3306 jdbc.dbName=eforum jdbc.driver_class=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://${jdbc.host}:${jdbc.port}/${jdbc.dbName} jdbc.username=root jdbc.password=123456

读取jdbc.url (支持${}格式变量引用)

Configure configure = ConfigReaderFactory.getConfigure("config");
		
System.out.println(configure.getString("jdbc.url"));

2、注解式读取

对于上面的配置内容,使用注解读取的代码如下:

import org.junit.Test;

import com.github.aoshiguchen.framework.configure.annotation.Config;

public class ConfigUtilTest {
	
	@Config
	private String projectName;
	
	@Config("jdbc.port")
	private int port;
	
	@Config("jdbc.url")
	private String url;
	
	{
		/**
		 * 与spring整合时,可以将这行代码置入spring前置处理器
		 * sprign容器初始化时就会自动注入
		 */
		ConfigUtil.inject("config", this);
	}
	
	//注入式读取配置
	@Test
	public void test1(){
		System.out.println(projectName);
		System.out.println(port);
		System.out.println(url);
	}
	
	//直接读取
	@Test
	public void test2(){
		Configure configure = ConfigReaderFactory.getConfigure("config");
		
		System.out.println(configure.getString("jdbc.host"));
		System.out.println(configure.getString("jdbc.driver_class"));
		System.out.println(configure.getString("jdbc.username"));
	}
	
}

联系我们

笔者QQ 1052045476

nodejs交流群 527393872

java交流群 527393872

c/c++语言交流群 251975693

Versions

Version
0.0.2
0.0.1