{"id":17350444,"url":"https://github.com/codecshekhar/spring-boot-application-runner-example","last_synced_at":"2025-03-27T12:19:22.298Z","repository":{"id":256978708,"uuid":"856996341","full_name":"CodeCshekhar/spring-boot-application-runner-example","owner":"CodeCshekhar","description":"This repository contains spring-boot-application-runner concepts to illustrate its advantages","archived":false,"fork":false,"pushed_at":"2024-09-13T15:56:10.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T12:19:18.542Z","etag":null,"topics":["application","runner","spring-boot"],"latest_commit_sha":null,"homepage":"","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/CodeCshekhar.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":"2024-09-13T15:50:33.000Z","updated_at":"2024-12-04T07:09:28.000Z","dependencies_parsed_at":"2024-09-14T06:56:56.889Z","dependency_job_id":null,"html_url":"https://github.com/CodeCshekhar/spring-boot-application-runner-example","commit_stats":null,"previous_names":["chandrashekharwagh/spring-boot-application-runner","codecshekhar/spring-boot-application-runner-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeCshekhar%2Fspring-boot-application-runner-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeCshekhar%2Fspring-boot-application-runner-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeCshekhar%2Fspring-boot-application-runner-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeCshekhar%2Fspring-boot-application-runner-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeCshekhar","download_url":"https://codeload.github.com/CodeCshekhar/spring-boot-application-runner-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245841760,"owners_count":20681196,"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":["application","runner","spring-boot"],"created_at":"2024-10-15T17:06:58.299Z","updated_at":"2025-03-27T12:19:22.283Z","avatar_url":"https://github.com/CodeCshekhar.png","language":"Java","readme":"# Spring Boot Application Runner\n\n## Overview\n\nSpring Boot Application Runner is a feature that allows you to execute code after the Spring ApplicationContext has been initialized. It's particularly useful for running specific tasks or initializing components when your application starts up.\n\n## Features\n\n- **Post-Initialization Execution**: Run code after Spring Boot has fully started.\n- **Multiple Runners**: Define and use multiple Application Runners in a single application.\n- **Ordering**: Control the execution order of multiple runners.\n- **Dependency Injection**: Utilize Spring's dependency injection in your runners.\n- **Exception Handling**: Proper exception handling during application startup.\n- **Conditional Execution**: Use Spring's conditional annotations to control when runners execute.\n\n## Getting Started\n\n1. **Add Dependency**\n\n   Ensure you have the Spring Boot starter in your `pom.xml`:\n\n   ```xml\n   \u003cdependency\u003e\n       \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n       \u003cartifactId\u003espring-boot-starter\u003c/artifactId\u003e\n   \u003c/dependency\u003e\n   ```\n\n2. **Create an Application Runner**\n\n   Implement the `ApplicationRunner` interface:\n\n   ```java\n   import org.springframework.boot.ApplicationArguments;\n   import org.springframework.boot.ApplicationRunner;\n   import org.springframework.stereotype.Component;\n\n   @Component\n   public class MyApplicationRunner implements ApplicationRunner {\n       @Override\n       public void run(ApplicationArguments args) throws Exception {\n           System.out.println(\"This will be executed after the application starts\");\n       }\n   }\n   ```\n\n3. **Run Your Application**\n\n   Start your Spring Boot application as usual. The `run` method of your Application Runner will be executed automatically.\n\n## Configuration\n\nYou can configure multiple Application Runners and control their order:\n\n```java\n@Component\n@Order(1)\npublic class FirstRunner implements ApplicationRunner {\n    // Implementation\n}\n\n@Component\n@Order(2)\npublic class SecondRunner implements ApplicationRunner {\n    // Implementation\n}\n```\n\n## Usage Examples\n\n1. **Database Initialization**\n\n   ```java\n   @Component\n   public class DatabaseInitializer implements ApplicationRunner {\n       @Autowired\n       private DataSource dataSource;\n\n       @Override\n       public void run(ApplicationArguments args) throws Exception {\n           // Initialize database schema or load initial data\n       }\n   }\n   ```\n\n2. **Cache Warming**\n\n   ```java\n   @Component\n   public class CacheWarmer implements ApplicationRunner {\n       @Autowired\n       private CacheManager cacheManager;\n\n       @Override\n       public void run(ApplicationArguments args) throws Exception {\n           // Pre-load data into cache\n       }\n   }\n   ```\n\n## Best Practices\n\n1. Keep Application Runner logic concise and focused.\n2. Use dependency injection to access other Spring beans.\n3. Handle exceptions properly to ensure clean application startup.\n4. Use `@Order` annotation to control execution order when necessary.\n5. Consider using `@Conditional` annotations for environment-specific runners.\n\n## Documentation\n\nFor more detailed information, refer to the official Spring Boot documentation:\n- [Spring Boot Application Runner](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-command-line-runner)\n\n## Support\n\nIf you encounter issues or have questions:\n\n1. Check the [Spring Boot documentation](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/)\n2. Visit the [Spring Community Forums](https://community.spring.io/)\n3. Report issues on the [Spring Boot GitHub repository](https://github.com/spring-projects/spring-boot/issues)\n\n## Contributing\n\nContributions to Spring Boot are welcome! Please refer to the [Spring Boot Contributing Guide](https://github.com/spring-projects/spring-boot/blob/main/CONTRIBUTING.adoc) for more information.\n\n## License\n\nSpring Boot is open source software released under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecshekhar%2Fspring-boot-application-runner-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodecshekhar%2Fspring-boot-application-runner-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecshekhar%2Fspring-boot-application-runner-example/lists"}