{"id":18463974,"url":"https://github.com/unleash/unleash-spring-boot-starter","last_synced_at":"2025-07-25T04:04:49.647Z","repository":{"id":59351730,"uuid":"531765197","full_name":"Unleash/unleash-spring-boot-starter","owner":"Unleash","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-22T13:59:59.000Z","size":122,"stargazers_count":10,"open_issues_count":2,"forks_count":9,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-22T14:29:01.430Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Unleash.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-02T03:13:58.000Z","updated_at":"2025-04-22T14:00:03.000Z","dependencies_parsed_at":"2023-02-14T04:02:00.220Z","dependency_job_id":"9454f623-9a97-44d3-ac7e-3f253b61a01d","html_url":"https://github.com/Unleash/unleash-spring-boot-starter","commit_stats":{"total_commits":64,"total_committers":7,"mean_commits":9.142857142857142,"dds":0.234375,"last_synced_commit":"972d43ac54360e6613d1e002160cc223755e4c7b"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/Unleash/unleash-spring-boot-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unleash%2Funleash-spring-boot-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unleash%2Funleash-spring-boot-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unleash%2Funleash-spring-boot-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unleash%2Funleash-spring-boot-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Unleash","download_url":"https://codeload.github.com/Unleash/unleash-spring-boot-starter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unleash%2Funleash-spring-boot-starter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266952445,"owners_count":24011502,"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","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-11-06T09:08:31.062Z","updated_at":"2025-07-25T04:04:49.624Z","avatar_url":"https://github.com/Unleash.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spring boot starter for Unleash Client SDK for Java\nThis provides a springboot starter for the official Unleash Client SDK for Java. \nThis takes care of the required bootstrapping and creation of Unleash client. This also \nprovides a annotation based approach to feature toggling similar to the functionality provided\nby FF4J client library. This also takes care of adding the unleash sdk as a transitive\ndependency.\n\n## Getting started\nThe following dependency needs to be added to the springboot project pom.\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.getunleash\u003c/groupId\u003e\n    \u003cartifactId\u003espringboot-unleash-starter\u003c/artifactId\u003e\n    \u003cversion\u003eLatest version here\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Add the following to application.yaml\n```yaml\nio:\n  getunleash:\n    app-name: \u003capplication-name\u003e\n    instance-id: \u003cinstance-id\u003e\n    environment: \u003cenvironment\u003e\n    api-url: \u003curl\u003e\n    api-token: \u003ctoken\u003e\n```\nex:\n```yaml\nio:\n  getunleash:\n    app-name: springboot-test\n    instance-id: instance x\n    environment: development\n    api-url: http://unleash.herokuapp.com/api/\n    api-token: '*:development.21a0a7f37e3ee92a0e601560808894ee242544996cdsdsdefgsfgdf'\n```\n- The configuration takes care of creating configuring `UnleashConfig` and creating an instance of `io.getunleash.Unleash`.\n- This takes care of binding all strategy instances (in-built and custom) to the `Unleash` instance.\n\n### Including Spring Security Details in the Unleash Context\nProvide an `UnleashContextProvider` bean to add details that Unleash can leverage when evaluating toggle strategies:\n```java\n@Bean\n@ConditionalOnMissingBean\npublic UnleashContextProvider unleashContextProvider(final UnleashProperties unleashProperties) {\n    return () -\u003e {\n        UnleashContext.Builder builder = UnleashContext.builder();\n        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();\n        if (principal instanceof User) {\n            builder.userId(((User)principal).getUsername());\n        }\n        \n        return builder\n            .appName(unleashProperties.getAppName())\n            .environment(unleashProperties.getEnvironment())\n            .build();\n    };\n}\n```\n\n### Usage\n- Create a feature toggle `demo-toggle` on unleash server and enabled it.\n- Create an interface FeatureDemoService and 2 implementation\n```java\npublic interface FeatureDemoService {\n    String getDemoString(String name);\n}\n```\n```java\n@Service(\"featureOldService\")\npublic class FeatureDemoOldServiceImpl implements FeatureDemoService {\n    public String getDemoString(String name) {\n        return \"old implementation\";\n    }\n}\n```\n```java\n@Service(\"featureNewService\")\npublic class FeatureDemoNewServiceImpl implements FeatureDemoService {\n    public String getDemoString(String name) {\n        return \"New implementation\";\n    }\n}\n```\n- The requirement is that if the feature is enabled on the server, the new service implementation is used.\n- To get the above functionality add the `@Toggle` annotation to the interface,\n- If `Context` annotation is not used and UnleashContext is explicitly passed as a method parameter\n```java\nimport io.getunleash.UnleashContext;\nimport org.unleash.features.annotation.Toggle;\n\npublic interface FeatureDemoService {\n    @Toggle(name=\"demo-toggle\", alterBean=\"featureNewService\")\n    String getDemoString(String name, UnleashContext context);\n}\n```\n- If `@Context` annotation is used to set UnleashContext\n```java\nimport io.getunleash.UnleashContext;\nimport org.unleash.features.annotation.Toggle;\n\npublic interface FeatureDemoService {\n    @Toggle(name=\"demo-toggle\", alterBean=\"featureNewService\")\n    String getDemoString(String name);\n}\n```\n`FeatureDemoService` is injected where required.\n- If `Context` annotation is not used and UnleashContext is explicitly passed as a method parameter\n```java\nimport io.getunleash.UnleashContext;\nimport org.unleash.features.annotation.Toggle;\n\npublic interface FeatureDemoService {\n    @Toggle(name=\"demo-toggle\", alterBean=\"featureNewService\")\n    String getDemoString(String name, UnleashContext context);\n}\n```\n```java\n@RestController\n@RequestMapping(\"/feature\")\npublic class FeatureDemoController {\n    private final FeatureDemoService featureDemoService;\n    \n    public FeatureDemoController(@Qualifier(\"featureOldService\") final FeatureDemoService featureDemoService) {\n        this.featureDemoService = featureDemoService;\n    }\n    \n    @GetMapping\n    public String feature(@RequestParam final String name) {\n        return featureDemoService.getDemoString(name, UnleashContext.builder().addProperty(\"name\", name).build());\n    }\n}\n```\n- If `@Context` annotation is used to set UnleashContext\n```java\nimport io.getunleash.UnleashContext;\nimport org.unleash.features.annotation.Toggle;\n\npublic interface FeatureDemoService {\n    @Toggle(name=\"demo-toggle\", alterBean=\"featureNewService\")\n    String getDemoString(String name);\n}\n```\n```java\n@RestController\n@RequestMapping(\"/feature\")\npublic class FeatureDemoController {\n    private final FeatureDemoService featureDemoService;\n    \n    public FeatureDemoController(@Qualifier(\"featureOldService\") final FeatureDemoService featureDemoService) {\n        this.featureDemoService = featureDemoService;\n    }\n    \n    @GetMapping\n    public String feature(@RequestParam @Context(name = \"name\") final String name) {\n        return featureDemoService.getDemoString(name);\n    }\n}\n```\n\n- With the above, if the `demo-toggle` feature is enabled, the `featureNewService` is called even though `featureOldService` was injected.\n\n### Example for variants\n- Toggle annotation has support for variants. It can be used as follows:\n  ```java\n    @Toggle(name = \"background-color-feature\",\n            variants = @FeatureVariants(\n                    fallbackBean = \"noBackgroundColorService\",\n                    variants = {\n                            @FeatureVariant(name = \"green-background-variant\", variantBean = \"greenBackgroundColorService\"),\n                            @FeatureVariant(name = \"red-background-variant\", variantBean = \"redBackgroundColorService\")\n                    }))\n  ```\n  - In the above example, there are 2 variants `green-background-variant` and `red-background-variant` defined in unleash. Here the implementation to be used for each variant is defined. `fallbackBean` is the implementation that will be used if a variant to bean mapping is not found.\n    \n\n\n- git link to example app below:\n  - https://github.com/praveenpg/unleash-starter-demo\n\n\n## Development\n\n### Releasing a new version\n\nIf you have push rights to the repo, make sure there are no modifications that haven't been checked in. Then run\n```bash\nmvn release:prepare\n```\nand answer the prompts for new release version. \n\nOnce that's done, a new tag should've been created in the repo, and the [deploy release](./.github/workflows/deploy-release.yml) workflow will do the actual deploy.\n\nThen, run mvn release:clean to clean your repo for release artifacts which only clutters up the main branch. This will leave you \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funleash%2Funleash-spring-boot-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funleash%2Funleash-spring-boot-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funleash%2Funleash-spring-boot-starter/lists"}