{"id":22611224,"url":"https://github.com/bzdgn/singleton-configuration-manager-example","last_synced_at":"2025-03-28T23:20:38.940Z","repository":{"id":81112741,"uuid":"123815086","full_name":"bzdgn/singleton-configuration-manager-example","owner":"bzdgn","description":"A Configuration Manager Class with the GOF Design Pattern Singleton","archived":false,"fork":false,"pushed_at":"2018-03-04T19:00:00.000Z","size":188,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-03T09:47:47.009Z","etag":null,"topics":["configuration","configuration-files","configuration-management","design-pattern","design-patterns","java","object-oriented-programming","oop-examples","properties","properties-loader","singleton","singleton-pattern"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bzdgn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-04T18:10:12.000Z","updated_at":"2022-11-08T22:05:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"4874aefc-6b4c-48a4-b1b2-8ad021c77edd","html_url":"https://github.com/bzdgn/singleton-configuration-manager-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bzdgn%2Fsingleton-configuration-manager-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bzdgn%2Fsingleton-configuration-manager-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bzdgn%2Fsingleton-configuration-manager-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bzdgn%2Fsingleton-configuration-manager-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bzdgn","download_url":"https://codeload.github.com/bzdgn/singleton-configuration-manager-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246112658,"owners_count":20725301,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","configuration-files","configuration-management","design-pattern","design-patterns","java","object-oriented-programming","oop-examples","properties","properties-loader","singleton","singleton-pattern"],"created_at":"2024-12-08T16:09:50.861Z","updated_at":"2025-03-28T23:20:38.930Z","avatar_url":"https://github.com/bzdgn.png","language":"Java","readme":"Singleton Configuration Manager Example\n=======================================\nThis is the Configuration Manager class I've written a long time ago to use as a general\nconfig manager in my projects. It is a simple Gang-Of-Four Singleton design pattern.\nWith this simple class, you can use the properties file and access it with this\nsingle singleton configuration manager.\n\nTOC\n---\n1- [Properties File](#properties-file) \u003cbr/\u003e\n2- [Setting Up The Environmental Variable](#setting-up-the-environmental-variable) \u003cbr/\u003e\n3- [States Of The ConfigManager](#states-of-the-configmanager) \u003cbr/\u003e\n\nProperties File\n---------------\nThere are two locations that properties file can be located;\n\n1- Properties file can be either on the base dir, or if you are using a build tool like maven,\nit can be in the resource directory (which is: src/main/resources).\n\n2- If an environmental variable is defined, then the value of the env-variable will be the\nlocation of the properties file.\n\nThe logic is simple, the program first checks whether an environmental variable is defined.\nIf so, it will check if there is a file on the value of the environmental variable which is\nactually the location of the directory. If there is the file, then config-manager is going\nto use it, if not, it will System.exit(1).\n\nIf the environmental variable is not set, the config-manager will check the base dir, or the\nbase resource directory to check whether if there is a properties file. If it is in there,\nit will use it, if not, again, it will System.exit(1).\n\nThe name of the properties file is hardcoded inside the ConfigManager class.\n\n[Go back to TOC](#toc)\n\nSetting Up The Environmental Variable\n-------------------------------------\nYou can set up the environmental variable in windows as below;\n\n![Setting-Up-Environmental-Variable](https://raw.githubusercontent.com/bzdgn/singleton-configuration-manager-example/master/ScreenShots/00_HOW_TO_SET_ENV_VAR.PNG)\n\nIf the env-variable is set, then inside the Config static class which is inside the ConfigManager,\nyou can hardcode the name of the environmental variable.\n\n[Go back to TOC](#toc)\n\nStates Of The ConfigManager\n---------------------------\n1- Environmental Variable Set But There Is No Properties File In The Target Directory\n\n![Env-Is-Set-But-No-Props-File-In-Target-Dir](https://raw.githubusercontent.com/bzdgn/singleton-configuration-manager-example/master/ScreenShots/01_ENV_IS_SET_BUT_NO_FILE.PNG)\n\n2- Environmental Variable Set And There Is Properties File In The Target Directory\n\n![Env-Is-Set-But-Props-File-In-Target-Dir](https://raw.githubusercontent.com/bzdgn/singleton-configuration-manager-example/master/ScreenShots/02_ENV_IS_SET_AND_FILE_IS_FOUND.PNG)\n\n3- Environmental Variable Is Not Set And There Is Properties File In The Base Dir\n\n![Env-Is-Not-Set-But-Props-File-In-Base-Dir](https://raw.githubusercontent.com/bzdgn/singleton-configuration-manager-example/master/ScreenShots/03_NO_ENV_IS_SET_FILE_IS_ON_WORKING_DIR.PNG)\n\n4- Environmental Variable Is Not Set And No Properties File In The Base Dir\n\n![Env-Is-Not-Set-And-No-Props-File-In-Base-Dir](https://raw.githubusercontent.com/bzdgn/singleton-configuration-manager-example/master/ScreenShots/04_NO_ENV_IS_SET_FILE_IS_NOT_FOUND_ON_WORKING_DIR.PNG)\n\n[Go back to TOC](#toc)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbzdgn%2Fsingleton-configuration-manager-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbzdgn%2Fsingleton-configuration-manager-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbzdgn%2Fsingleton-configuration-manager-example/lists"}