{"id":36236651,"url":"https://github.com/constretto/constretto-core","last_synced_at":"2026-01-11T06:00:55.661Z","repository":{"id":568708,"uuid":"200121","full_name":"constretto/constretto-core","owner":"constretto","description":"Constretto is a versatile configuration toolkit for the JVM implemented in Java","archived":false,"fork":false,"pushed_at":"2023-04-05T11:59:52.000Z","size":1493,"stargazers_count":65,"open_issues_count":16,"forks_count":21,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-07-08T06:47:49.595Z","etag":null,"topics":["configuration","java"],"latest_commit_sha":null,"homepage":"https://github.com/constretto","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/constretto.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2009-05-13T18:53:22.000Z","updated_at":"2024-08-18T10:17:53.000Z","dependencies_parsed_at":"2023-07-05T15:02:51.109Z","dependency_job_id":null,"html_url":"https://github.com/constretto/constretto-core","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"purl":"pkg:github/constretto/constretto-core","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constretto%2Fconstretto-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constretto%2Fconstretto-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constretto%2Fconstretto-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constretto%2Fconstretto-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/constretto","download_url":"https://codeload.github.com/constretto/constretto-core/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constretto%2Fconstretto-core/sbom","scorecard":{"id":303198,"data":{"date":"2025-08-11","repo":{"name":"github.com/constretto/constretto-core","commit":"73c9351642ef523c8f64eac999e1e6ef5a87e0d9"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.8,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/25 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:28","Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:29","Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1","Warn: no topLevel permission defined: .github/workflows/maven.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/constretto/constretto-core/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/constretto/constretto-core/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:59: update your workflow using https://app.stepsecurity.io/secureworkflow/constretto/constretto-core/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:72: update your workflow using https://app.stepsecurity.io/secureworkflow/constretto/constretto-core/codeql-analysis.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/maven.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/constretto/constretto-core/maven.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/maven.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/constretto/constretto-core/maven.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/maven.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/constretto/constretto-core/maven.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/maven.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/constretto/constretto-core/maven.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/maven.yml:46: update your workflow using https://app.stepsecurity.io/secureworkflow/constretto/constretto-core/maven.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/maven.yml:48: update your workflow using https://app.stepsecurity.io/secureworkflow/constretto/constretto-core/maven.yml/master?enable=pin","Info:   0 out of   9 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":7,"reason":"SAST tool detected but not run on all commits","details":["Info: SAST configuration detected: CodeQL","Warn: 0 commits out of 6 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":9,"reason":"1 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-j288-q9x7-2f5v"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-17T21:17:31.308Z","repository_id":568708,"created_at":"2025-08-17T21:17:31.308Z","updated_at":"2025-08-17T21:17:31.308Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28293188,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T04:44:51.577Z","status":"ssl_error","status_checked_at":"2026-01-11T04:44:44.232Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","java"],"created_at":"2026-01-11T06:00:53.238Z","updated_at":"2026-01-11T06:00:55.621Z","avatar_url":"https://github.com/constretto.png","language":"Java","readme":"Constretto\n==========\n\nConstretto is as configuration management framework for Java applications.\nIt allows you to “tag” configuration values, so that Constretto could choose the correct value at runtime.\n\nIt also works as a bridge between different configuration formats, and currently Java property files, Ini files, and Java Beans are supported.\nStarting with Constretto 3 all releases requires Java 8 or later   \n\n[![Java CI with Maven](https://github.com/constretto/constretto-core/actions/workflows/maven.yml/badge.svg)](https://github.com/constretto/constretto-core/actions/workflows/maven.yml)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.constretto/constretto-core/badge.svg)](https://mvnrepository.com/artifact/org.constretto/constretto-core)\n[![Coverage](https://codecov.io/gh/constretto/constretto-core/branch/master/graph/badge.svg?token=BQ9RdTTfL6)](https://codecov.io/gh/constretto/constretto-core)\n[![Open Source Helpers](https://www.codetriage.com/constretto/constretto-core/badges/users.svg)](https://www.codetriage.com/constretto/constretto-core)\n\n## How to Install?\nConstretto is built with maven and deployed to the central maven repository, so if you are using maven, you can simply add Constretto as dependencies in your pom:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.constretto\u003c/groupId\u003e\n    \u003cartifactId\u003econstretto-api\u003c/artifactId\u003e\n    \u003cversion\u003e3.0.0-BETA4\u003c/version\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.constretto\u003c/groupId\u003e\n    \u003cartifactId\u003econstretto-core\u003c/artifactId\u003e\n    \u003cversion\u003e3.0.0-BETA4\u003c/version\u003e\n    \u003cscope\u003eruntime\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\nIf you would like to use the Spring support add:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.constretto\u003c/groupId\u003e\n    \u003cartifactId\u003econstretto-spring\u003c/artifactId\u003e\n    \u003cversion\u003e3.0.0-BETA1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n*Note*: The Spring extension is now a [separate project](//github.com/constretto/constretto-spring)\n\nIf you would like to use the Constretto Junit support add:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.constretto\u003c/groupId\u003e\n    \u003cartifactId\u003econstretto-test\u003c/artifactId\u003e\n    \u003cversion\u003e3.0.0-BETA4\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n\n## Changes in version 3\n\nChanges in [previous versions](changelog.md) (pre version 3)\n\n## Features\n\n### Constructor injection\n* only one constructor per class may be have the @Configure annotation or Constretto will complain\n\nGiven the following POJO:\n```java\npublic class SimpleConstructorInjectableBean {\n\n    private String key1;\n\n    @Configure\n    public SimpleConstructorInjectableBean(final String key1) {\n        this.key1 = key1;\n    }\n\n    public String getKey1() {\n        return key1;\n    }\n}\n```\nAn instance may be Constructed using the \"as\" method:\n```java\nConstrettoConfiguration configuration = ...\nSimpleConstructorInjectableBean configBean = configuration.as(SimpleConstructorInjectableBean.class);\n```\n\nIf you use Spring and have enabled Constretto-Spring support you can mix @Autowired and @Configure annotations:\n```java\npublic class AutowiredAndConfiguredConstructorInjectionBean {\n\n    private SimpleConstructorInjectableBean simpleConstructorInjectableBean;\n\n    private String key2;\n\n    @Autowired\n    @Configure\n    public AutowiredAndConfiguredConstructorInjectionBean(final SimpleConstructorInjectableBean simpleConstructorInjectableBean,\n                                                          final String key2) {\n        this.simpleConstructorInjectableBean = simpleConstructorInjectableBean;\n        this.key2 = key2;\n    }\n\n    public SimpleConstructorInjectableBean getSimpleConstructorInjectableBean() {\n        return simpleConstructorInjectableBean;\n    }\n\n    public String getKey2() {\n        return key2;\n    }\n}\n```\n```xml\n\u003cbeans xmlns=\"http://www.springframework.org/schema/beans\"\n       xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n       xmlns:constretto=\"http://constretto.org/schema/constretto\"\n       xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\n       http://constretto.org/schema/constretto http://constretto.org/schema/constretto/constretto-1.2.xsd\"\u003e\n\n    \u003c!--- annotation-config must be \"true\" for constructor injection to work ---\u003e\n    \u003cconstretto:configuration annotation-config=\"true\" property-placeholder=\"false\"\u003e\n        \u003cconstretto:stores\u003e\n            \u003cconstretto:properties-store\u003e\n                \u003cconstretto:resource location=\"classpath:properties/test1.properties\"/\u003e\n            \u003c/constretto:properties-store\u003e\n        \u003c/constretto:stores\u003e\n    \u003c/constretto:configuration\u003e\n    \u003cbean class=\"org.constretto.spring.configuration.helper.SimpleConstructorInjectableBean\"/\u003e\n    \u003cbean class=\"org.constretto.spring.configuration.helper.AutowiredAndConfiguredConstructorInjectionBean\" /\u003e\n\u003c/beans\u003e    \n```\n\n### Using the LdapConfigurationStore\n\nAdd LDAP entry either by using its distinguished name or by providing LDAP search parameters:\n```java\nfinal ConstrettoConfiguration configuration = new ConstrettoBuilder()\n    .createLdapConfigurationStore(initialDirContext)\n        .addDsn(\"cn=Kaare Nilsen,dc=constretto,dc=org\")\n        // all attributes in the given entry will be available (ie. configuration key \"cn\" will have the value \\\"Kaare Nilsen\")\n        .addDsnWithKey(\"sidekick\", \"cn=Jon-Anders Teigen,dc=constretto,dc=org\")\n        // maps LDAP attributes with prefix \"sidekick\". (ie. \"sidekick.cn\" will have the value \"Jon-Anders Teigen\")\n        .addUsingSearch(\"dc=constretto,dc=org\", \"(\u0026(cn=K*)(objectClass=inetOrgPerson))\", \"uid\")\n         // Adds all LDAP objects matching the query to configuration attributes prefixed with the value of the \"uid\" attribute\n         // ie. if the uid attribute for \"cn=Kaare Nilsen,dc=constretto,dc=org\" is \"kaare\", its \"cn\" attribute will be available as \"kaare.cn\"\n    .done()\n    .getConfiguration();\n```\n\n### Using the ConstrettoRule in a JUnit test\n\nConstretto will help you setting the specified tags or environment settings for a Junit test by providing ConstrettoRule\nto be used as either a [@ClassRule](https://github.com/junit-team/junit/wiki/Rules#classrule) (running before class initialization like @BeforeClass and @AfterClass) or a [@Rule](https://github.com/junit-team/junit/wiki/Rules#rules) (wrapping a test method invocation like @Before and @After).\n\nThe @ClassRule use case is useful if you use a custom JUnitRunner such as the ones provided by Spring Test as it will ensure\nthat specified tags are set before the JUnitRunner is invoked (and reset to its previous value afterwords).\n@ClassRule may also be used for JUnit Suites.\n\n```java\n@Tags({\"purejunit\", \"test\"})\npublic class ConstrettoRuleTest {\n    @Rule\n    public ConstrettoRule constrettoRule = new ConstrettoRule();\n\n    @Test\n    public void someTestRequiringEnvironmentTagsToBeSet() {\n        ConstrettoConfiguration configuration = new ConstrettoBuilder().createSystemPropertiesStore().getConfiguration();\n        // current tags will be \"purejunit\" and \"test\"\n        // more logic here...\n    }\n}\n```\n#### Integration with Constretto-Spring\n\nYou may also use ConstrettoRule with the @Environment annotation from Constretto Spring\n\n```java\nimport org.constretto.ConstrettoConfiguration;\nimport org.constretto.spring.ConfigurationAnnotationConfigurer;\nimport org.constretto.spring.annotation.Environment;\nimport org.constretto.spring.internal.resolver.DefaultAssemblyContextResolver;\nimport org.constretto.test.Environment;\nimport org.junit.ClassRule;\nimport org.junit.Test;\nimport org.junit.runner.RunWith;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.test.context.ContextConfiguration;\n\n@Environment(\"junit\")\n@RunWith(ConstrettoSpringJUnit4ClassRunner.class)\n@ContextConfiguration(classes = MyTest.TestConfiguration.class)\npublic class MyTest {\n\n  // Using Spring Java config for this example\n  @Configuration\n  public static class TestConfiguration {\n\n    @Bean\n    public static ConstrettoConfiguration constrettoConfiguration() {\n      return new ConstrettoBuilder(true).getConfiguration();\n    }\n\n    // Using Spring Java config for this example\n    @Bean\n    public static ConfigurationAnnotationConfigurer configurationAnnotationConfigurer(final ConstrettoConfiguration configuration) {\n      return new ConfigurationAnnotationConfigurer(configuration, new DefaultAssemblyContextResolver());\n    }\n  }\n\n\n  // The current environment value will be injected by the ConfigurationAnnotationConfigurer\n  // It is enabled by default in Spring XML configurations if you include the \"\u003cconstretto:configuration/\u003e\" tag\n  @Environment\n  private List\u003cString\u003e injectedEnvironment;\n\n  // ClassRules will be invoked before the class (like @BeforeClass/@AfterClass) and thus need to be static\n  @ClassRule\n  public static ConstrettoRule constrettoRule = new ConstrettoRule();\n\n  @Test\n  public void testApplyEnvironment() throws Exception {\n\n    assertArrayEquals(new String[]{\"junit\"}, injectedEnvironment.toArray(new String[1]));\n\n  }\n}\n```\n\n\n\n## How to configure Constretto?\n\n### Using Java API\n\nConstretto provides a fluent API to be used in any Java application. Its main interface is ConstrettoConfiguration, that supplies methods to query for values in your configuration. To initialize the ConstrettoConfiguration interface, use the supplied ConstrettoBuilder as shown in the example below:\n\n```java\nConstrettoConfiguration config =\n                new ConstrettoBuilder()\n                        .createPropertiesStore()\n                            .addResource(new DefaultResourceLoader().getResource(\"classpath:test.properties\"))\n                            .addResource(new DefaultResourceLoader().getResource(\"file:test2.properties\"))\n                        .done()\n                        .createIniFileConfigurationStore()\n                            .addResource(new DefaultResourceLoader().getResource(\"classpath:test.ini\"))\n                        .done()\n                        .createObjectConfigurationStore()\n                            .addObject(new Object())\n                        .done()\n                        .createSystemPropertiesStore()\n                        .getConfiguration();\n```\n\n### Using Spring framework\n\nConstretto works very well in a Spring environment, It provides a namespace for Spring xml configuration files, to build a ConstrettoConfiguration object, and also provides a ProperyPlaceHolder to allow values in Spring xml files to be resolved from Constretto, and also a BeanPostProcessor that enables ConfigurationInjection.\n\nTo tell Spring to use Constretto:\n\n#### XML Contexts\n```xml\n\u003cbeans xmlns=\"http://www.springframework.org/schema/beans\"\n       xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n       xmlns:constretto=\"http://constretto.org/schema/constretto\"\n       xsi:schemaLocation=\"http://www.springframework.org/schema/beans\n           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\n           http://constretto.org/schema/constretto\n           http://constretto.org/schema/constretto/constretto-1.2.xsd\"\u003e\n\n    \u003cconstretto:configuration annotation-config=\"true\" property-placeholder=\"true\"\u003e\n        \u003cconstretto:stores\u003e\n            \u003cconstretto:properties-store\u003e\n                \u003cconstretto:resource location=\"classpath:properties/test1.properties\"/\u003e\n            \u003c/constretto:properties-store\u003e\n        \u003c/constretto:stores\u003e\n    \u003c/constretto:configuration\u003e\n\u003c/beans\u003e\n```\n#### Java Contexts\n```java\n    @org.constretto.spring.annotation.Constretto\n    @org.springframework.context.annotation.Configuration\n    public class Context {\n\n        // Add public static non-arg factory method that creates a ConstrettoConfiguration\n        public static ConstrettoConfiguration constrettoConfiguration() {\n            return new ConstrettoBuilder(true).getConfiguration();\n        }\n\n    }\n```\n\n\n## How to use Constretto in your application?\n\n### Using Java API\n\nNow that you've configured Constretto, by Java API or Spring, you may query your configuration using the methods in the ConstrettoConfiguration interface like in the examples below:\n\n```java\n// Simple lookup\nString aDataSourceUrl = configuration.evaluateToString(\"datasources.customer.url\");\n```\n\n### Configuration Injection - Annotation Based\n\nIn much the same way as dependency injection work in e.g. Spring and Guice, Constretto allows you to inject configuration into your classes.\nIt supports injection in fields, and methods as seen in the example below:\n\nJava class to be injected with configuration:\n\n```java\npublic class DataSourceConfiguration {\n\n    private String myUrl;\n    private String myPassword;\n    private Integer version;\n\n    // When no expression is explicitly given Constretto will use field name as key\n    @Configuration\n    private String vendor;\n\n    @Configuration(\"username\")\n    private String myUsername;\n\n    @Configure\n    public void configure(String url, @Configuration(\"password\") String secret) {\n        this.myUrl = url;\n        this.myPassword = secret;\n    }\n\n    @Configure\n    public void setVersion(Integer version) {\n        this.version = version;\n    }\n\n    public String getUrl() {\n        return myUrl;\n    }\n\n    public String getUsername() {\n        return myUsername;\n    }\n\n    public String getPassword() {\n        return myPassword;\n    }\n\n    public String getVendor() {\n        return vendor;\n    }\n\n    public Integer getVersion() {\n        return version;\n    }\n}\n```\nA test that shows this feature used with the Java API:\n\n```java\npublic class ConfigurationAnnotationsTest {\n    private ConstrettoConfiguration configuration;\n\n    @Before\n    public void prepareTests() {\n        setProperty(\"datasources.customer.url\", \"jdbc://url\");\n        setProperty(\"datasources.customer.username\", \"username\");\n        setProperty(\"datasources.customer.password\", \"password\");\n        setProperty(\"datasources.customer.vendor\", \"derby\");\n        setProperty(\"datasources.vendor\", \"derby\");\n        setProperty(\"datasources.customer.version\", \"10\");\n\n        configuration = new ConstrettoBuilder().createSystemPropertiesStore().getConfiguration();\n\n    }\n\n    @Test\n    public void createNewAnnotatedConfigurationObject() {\n        DataSourceConfiguration customerDataSource = configuration.at(\"datasources\").from(\"customer\").as(DataSourceConfiguration.class);\n        assertEquals(\"jdbc://url\", customerDataSource.getUrl());\n        assertEquals(\"username\", customerDataSource.getUsername());\n        assertEquals(\"password\", customerDataSource.getPassword());\n        assertEquals(\"derby\", customerDataSource.getVendor());\n        assertEquals(new Integer(10), customerDataSource.getVersion());\n    }\n\n    @Test\n    public void applyConfigrationToAnnotatedConfigurationObject() {\n        DataSourceConfiguration customerDataSource = new DataSourceConfiguration();\n        configuration.at(\"datasources\").from(\"customer\").on(customerDataSource);\n        assertEquals(\"derby\", customerDataSource.getVendor());\n        assertEquals(\"username\", customerDataSource.getUsername());\n        assertEquals(\"jdbc://url\", customerDataSource.getUrl());\n        assertEquals(\"password\", customerDataSource.getPassword());\n        assertEquals(new Integer(10), customerDataSource.getVersion());\n    }\n}\n```\n\nConfiguration Formats.\n----------------------\n\nConstretto currently supports four Configuration sources, and the\nfollowing sections shows how these are used, and how you may tag\nyour configuration values.\n\n### Java Property Files\n\nWhen using Java Property files, you may tag your entry with\n“[tag].\" if a key does not have a tag, it will be considered a default, and always be available\n\nExample:\n\n```INI\nsomedb.username=default username\n@production.somedb.username=username in production\n@systest.somedb.username=username in system test\n```\n\n###Ini Files\n\nConstretto also supports Ini files and here, sections are used as tags\n\nExample:\n\n```INI\n[default]\nsomedb.username=default username\n\n[production]\nsomedb.username=username in production\n\n[systest]\nsomedb.username=username in system test\n```\n\n### Java Objects used as configuration sources\n\nConstretto are able to use Java objects as configuration sources, and then annotations are used to indicate which tags are used.\nAlso the ConfigurationSource annotation can use an optional basePath attribute, that are prepended to the JavaBean property names found in the class resulting in \"somedb.username\" in the example below.\n\nExample:\n\n```java\n@ConfigurationSource(basePath =\"somedb\")\npublic class DefaultDataSourceConfigurer {\n\n    public String getUsername() {\n        return ”default username\";\n    }\n}\n\n@ConfigurationSource(basePath = \"somedb\", tag = \"production\")\npublic class ProductionDataSourceConfigurer {\n\n    public String getUsername() {\n        return \"username in production\";\n    }\n}\n```\n\n### System properties\n\nConstretto also allows values to be retrieved from System properties,\nbut here tags are not supported. Support for system properties are per\ndefault enabled\n\nHow to tell Constretto what tags to look up?\n--------------------------------------------\n\nConstretto uses a System property, or System environment property to\nknow what tags to look up. this property is called “CONSTRETTO_TAGS”\n\nExample:\n\n    $java MyApp -DCONSTRETTO_TAGS=tag1,tag2,tag3\n\n    Or\n\n    $export CONSTRETTO_TAGS=tag1,tag2,tag3\n    $java Myapp\n\nHow to report errors or request features?\n-----------------------------------------\n\nPlease use the [GitHub issue tracker](http://github.com/constretto/constretto-core/issues)\n\nFor further information and documentation\n-----------------------------------------\n\nConstretto has several more nice features, and they are covered in the reference manual at the Constretto official website: [http://constretto.github.io](http://constretto.github.io/)\n\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/constretto/constretto-core/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconstretto%2Fconstretto-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconstretto%2Fconstretto-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconstretto%2Fconstretto-core/lists"}