{"id":16344952,"url":"https://github.com/ericdallo/spring-s3-properties-loader","last_synced_at":"2025-03-23T00:32:42.163Z","repository":{"id":56322912,"uuid":"75938800","full_name":"ericdallo/spring-s3-properties-loader","owner":"ericdallo","description":"Spring component to load external properties from AWS S3","archived":false,"fork":false,"pushed_at":"2020-11-14T14:06:48.000Z","size":181,"stargazers_count":21,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T15:54:55.093Z","etag":null,"topics":["amazon","auto-complete","auto-refresh","aws","aws-s3","profile","properties","properties-loader","properties-refresh","s3","s3-bucket","services","spring","spring-bean","spring-s3","web"],"latest_commit_sha":null,"homepage":"https://ericdallo.github.io/spring-s3-properties-loader/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericdallo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-08T13:10:02.000Z","updated_at":"2023-07-08T18:09:59.000Z","dependencies_parsed_at":"2022-08-15T16:40:27.560Z","dependency_job_id":null,"html_url":"https://github.com/ericdallo/spring-s3-properties-loader","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericdallo%2Fspring-s3-properties-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericdallo%2Fspring-s3-properties-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericdallo%2Fspring-s3-properties-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericdallo%2Fspring-s3-properties-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericdallo","download_url":"https://codeload.github.com/ericdallo/spring-s3-properties-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245040235,"owners_count":20551297,"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":["amazon","auto-complete","auto-refresh","aws","aws-s3","profile","properties","properties-loader","properties-refresh","s3","s3-bucket","services","spring","spring-bean","spring-s3","web"],"created_at":"2024-10-11T00:29:31.834Z","updated_at":"2025-03-23T00:32:41.753Z","avatar_url":"https://github.com/ericdallo.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/ericdallo/spring-s3-properties-loader.svg?branch=master)](https://travis-ci.org/ericdallo/spring-s3-properties-loader)\r\n# Spring S3 Property Loader\r\n\u003cimg align=\"right\"  src=\"https://raw.githubusercontent.com/ericdallo/spring-s3-properties-loader/images/spring-icon.png?raw=true\" width=\"120\" height=\"120\"/\u003e\r\n\r\n_S3 Property Loader_ has the aim of allowing loading of Spring property files from S3 bucket, in order to guarantee stateless machine configuration.\r\n\r\nSpring PropertyConfigurer uses `PropertiesFactoryBean` to load property files from *AWS S3* bucket.\r\n\r\n## Install\r\n_Gradle_:\r\n```groovy\r\nrepositories {  \r\n   jcenter()  \r\n}\r\n```\r\n```groovy\r\ncompile \"com.spring.loader:s3-loader:3.0.0\"\r\n```\r\n_Maven_:\r\n```xml\r\n\u003cdependency\u003e\r\n  \u003cgroupId\u003ecom.spring.loader\u003c/groupId\u003e\r\n  \u003cartifactId\u003es3-loader\u003c/artifactId\u003e\r\n  \u003cversion\u003e3.0.0\u003c/version\u003e\r\n  \u003ctype\u003epom\u003c/type\u003e\r\n\u003c/dependency\u003e\r\n```\r\n\r\n## How to use\r\n\r\n- Adding this annotation to any spring managed bean\r\n```java\r\n@S3PropertiesLocation(\"my-bucket/my-folder/my-properties.yaml\")\r\n```\r\n- Using a specific profile to only load properties if the app is running with that profile\r\n```java\r\n@S3PropertiesLocation(value = \"my-bucket/my-folder/my-properties.properties\", profiles = \"production\")\r\n```\r\n- Load from a System env variable\r\n```java\r\n@S3PropertiesLocation(value = \"${AWS_S3_LOCATION}\", profiles = \"developer\")\r\n// or\r\n@S3PropertiesLocation(value = \"${AWS_S3_BUCKET}/application/my.properties\", profiles = \"developer\")\r\n```\r\n\r\n### Binding properties to a POJO\r\nYou can bind the externally loaded properties to a POJO as well.\r\n\r\nFor e.g., if you have a YAML file as\r\n```yaml\r\nzuul:\r\n  routes:\r\n    query1:\r\n      path: /api/apps/test1/query/**\r\n      stripPrefix: false\r\n      url: \"https://test.url.com/query1\"\r\n    query2:\r\n      path: /api/apps/test2/query/**\r\n      stripPrefix: false\r\n      url: \"https://test.url.com/query2\"\r\n    index1:\r\n      path: /api/apps/*/index/**\r\n      stripPrefix: false\r\n      url: \"https://test.url.com/index\"\r\n```\r\nThen you can bind the properties to a POJO using ConfigurationProperties:\r\n```java\r\n@Component\r\n@ConfigurationProperties(\"zuul\")\r\npublic class RouteConfig {\r\n    private Map\u003cString, Map\u003cString, String\u003e\u003e routes = new HashMap\u003c\u003e();\r\n\r\n    public void setRoutes(Map\u003cString, Map\u003cString, String\u003e\u003e routes) {\r\n        this.routes = routes;\r\n    }\r\n\r\n    public Map\u003cString, Map\u003cString, String\u003e\u003e getRoutes() {\r\n        return routes;\r\n    }\r\n}\r\n\r\n// or\r\n\r\n@Component\r\n@ConfigurationProperties(\"zuul\")\r\npublic class RouteConfig {\r\n    private Map\u003cString, Route\u003e routes;\r\n\r\n    public void setRoutes(Map\u003cString, Route\u003e routes) {\r\n        this.routes = routes;\r\n    }\r\n\r\n    public Map\u003cString, Route\u003e getRoutes() {\r\n        return routes;\r\n    }\r\n\r\n    public static class Route {\r\n        private String path;\r\n        private boolean stripPrefix;\r\n        String url;\r\n\r\n        public String getPath() {\r\n            return path;\r\n        }\r\n\r\n        public void setPath(String path) {\r\n            this.path = path;\r\n        }\r\n\r\n        public boolean isStripPrefix() {\r\n            return stripPrefix;\r\n        }\r\n\r\n        public void setStripPrefix(boolean stripPrefix) {\r\n            this.stripPrefix = stripPrefix;\r\n        }\r\n\r\n        public String getUrl() {\r\n            return url;\r\n        }\r\n\r\n        public void setUrl(String url) {\r\n            this.url = url;\r\n        }\r\n\r\n        @Override\r\n        public String toString() {\r\n            try {\r\n                return new ObjectMapper().writeValueAsString(this);\r\n            } catch (JsonProcessingException e) {\r\n                e.printStackTrace();\r\n            }\r\n            return this.toString();\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public String toString() {\r\n        try {\r\n            return new ObjectMapper().writeValueAsString(this);\r\n        } catch (JsonProcessingException e) {\r\n            e.printStackTrace();\r\n        }\r\n        return this.toString();\r\n    }\r\n}\r\n```\r\n\r\n### Refreshing properties in runtime\r\n\r\nYou can force your application to load properties from S3 again without restart. _S3 Properties Loader_ uses a [Spring Cloud](http://projects.spring.io/spring-cloud/) feature that allows the spring beans annotated with `@RefreshScope` to reload properties.\r\nTo work, *it is only necessary* to inject the `S3PropertiesContext` bean and call `refresh()` method. After this, _S3 Properties Loader_ will get properties again from s3 bucket defined previously and refresh your beans annotated with `@RefreshScope`.\r\n\r\n_tip_: You can create a endpoint that calls this class and refresh your application via endpoint or create a `@Scheduled` class which updates from time to time.\r\n\r\nExample:\r\n```java\r\n@RestController\r\npublic SomeController {\r\n\r\n   @Autowired\r\n   private S3PropertiesContext s3PropertiesContext;\r\n    \r\n   @PostMapping(\"/refresh-properties\")\r\n   public void refresh() {\r\n       s3PropertiesContext.refresh();\r\n   }\r\n}\r\n```\r\n## Requisites\r\n\r\nOfficial [spring aws sdk lib](https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-aws).\r\n\r\n## Problems and Issues\r\n\r\nFound some bug? Have some enhancement ? Open a Issue [here](https://github.com/ericdallo/spring-s3-properties-loader/issues)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericdallo%2Fspring-s3-properties-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericdallo%2Fspring-s3-properties-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericdallo%2Fspring-s3-properties-loader/lists"}