Skip to content

The library for managing the application properties that are stored externally or/and internally in the project or/and set as environment variables

License

Notifications You must be signed in to change notification settings

LenarBad/app-props

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Maven Central

Build Status Hits of Code Lines of Code

AppProps

The library for handling the application properties that are stored externally or/and internally in the project or/and set as environment variables

You can use different sources to config your application

  • Environmental variables
  • Properties files (usually .properties)
  • Files in JSON format

Files can be stored anywhere

  • Resource folder of your project
  • User Home folder
  • Any custom location on your computer
  • Somewhere in the network

How to add configs

To add a config file to your appProp you need pass a Resource file; with one of methods

  • addProperties(Source file)
  • addJsonProperty(Source file, String name, Class clazz)
  • addJsonPropertyAsList(Source file, String name, Class<T[]> clazz)

Examples

AppProps appProps = new AppProps()
                        .addProperties(new UserHomeFile("my-test.properties"))
                        .addProperties(new ResourceFile("my-app.properties"))
                        .addJsonProperty(new ResourceFile("test-users.json"), "testUser", User.class)
                        .addJsonPropertyAsList(new ResourceFile("test-cards.json"), "testCards", Card[].class)
                        .addYamlProperty(new ResourceFile("test-address.yml"), "shippingAddress", ShippingAddress.class)
                        .addYamlPropertyAsList(new ResourceFile("test-order-lines.yml"), "orderLines", OrderLine.class);

All environmental variables will be added automatically.
All configs will be read in the order that they were added to AppProps.

How to access property values

String dbPassword = appProps.value("password");
User testUser = appProp.valueAs("testUser", User.class);
ShippingAddress shippingAddress = (ShippingAddress) appProp.valueObject("shippingAddress", ShippingAddress.class);
List<Card> testCards = appProps.valueAsListOf("testCards", Card[].class);
List<OrderLine> orderLines = appProps.valueAsListOf("orderLines", OrderLine[].class);

List of objects YAML example

public class TestObject {

    private String value;

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
"value": "value 1"
---
"value": "value 2"

About

The library for managing the application properties that are stored externally or/and internally in the project or/and set as environment variables

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages