[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"global-header-tutorials-static":3,"article-dependency-pull-lookup-spring":4,"initial-similar-fetch":22},[],{"alias":5,"title":6,"description":7,"content":8,"thumbnail":9,"keywords":10,"categories":17,"tags":20,"createdAt":21},"dependency-pull-lookup-spring","Dependency Pull and Contextualized Dependency Lookup in Spring Framework","Dependency Pull and Contextualized Dependency Lookup IoC Types in Spring Framework","{\"type\":\"doc\",\"content\":[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"In this tutorial, we are going to look into the core concept of IoC, i.e dependency pull and dependency lookup in the Spring Framework.\"}]},{\"type\":\"heading\",\"attrs\":{\"textAlign\":null,\"level\":2},\"content\":[{\"type\":\"text\",\"text\":\"Dependency Pull\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"In the dependency pull mechanism, our component explicitly reaches out to the external container, registry, to pull the dependencies whenever needed, instead of injecting dependencies into our components at startup. \"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"Although the control  is still inverted i.e the control of object creation and lifecycle management is transferred to the framework.\"}]},{\"type\":\"codeBlock\",\"attrs\":{\"language\":\"java\"},\"content\":[{\"type\":\"text\",\"text\":\"public class MainApplication {\\n    public static void main(String[] args) {\\n        ApplicationContext container = new AnnotationConfigApplicationContext(NotificationAppConfig.class);\\n\\n        NotificationService manager = container.getBean(NotificationService.class);\\n       \\n        manager.sendAlert(\\\"Your package has shipped!\\\", \\\"john.doe@example.com\\\");\\n    }\\n}\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"Let's look into these code snippets. The \"},{\"type\":\"text\",\"marks\":[{\"type\":\"code\"}],\"text\":\"NotificationService\"},{\"type\":\"text\",\"text\":\" bean is retrieved from the ApplicationContext, which has all the registered beans in the application scope.\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"This instance is pulled so that its method \"},{\"type\":\"text\",\"marks\":[{\"type\":\"code\"}],\"text\":\"sendAlert\"},{\"type\":\"text\",\"text\":\" can be invoked to function.\"}]},{\"type\":\"heading\",\"attrs\":{\"textAlign\":null,\"level\":3},\"content\":[{\"type\":\"text\",\"text\":\"When is Dependency Pull actually useful?\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"The dependency pull is used while developing plugins, uses dynamic environments where the implementation doesn't know which beans are required  and must be fetched conditionally based on runtime data.\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"Let's look at the example of building a multitenant payment processor system where each tenant can choose their own payment processor. Here, we can't implement the single payment processor at startup need to provide the payment processor according to the tenant.\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"Here is a sample example to demonstrate this.\"}]},{\"type\":\"codeBlock\",\"attrs\":{\"language\":\"java\"},\"content\":[{\"type\":\"text\",\"text\":\"package org.csbyte.payment;\\n\\nimport org.springframework.context.ApplicationContext;\\nimport org.springframework.web.bind.annotation.*;\\n\\n@RestController\\n@RequestMapping(\\\"\u002Fapi\u002Fpayments\\\")\\npublic class PaymentController {\\n\\n    private final ApplicationContext context;\\n\\n    public PaymentController(ApplicationContext context) {\\n        this.context = context;\\n    }\\n\\n    @PostMapping(\\\"\u002Fprocess\\\")\\n    public void processTenantPayment(\\n        @RequestHeader(\\\"X-Tenant-ID\\\") String tenantId, \\n        @RequestBody PaymentPayload payload\\n    ) {\\n        \u002F\u002F Look up the tenant's configuration from a database\\n        String processorBeanName = tenantRegistry.getProcessorFor(tenantId); \u002F\u002F e.g., \\\"stripeProcessor\\\"\\n        \\n        \u002F\u002F PULL: Dynamically fetch the correct tenant-specific bean from the context at runtime\\n        PaymentProcessor processor = context.getBean(processorBeanName, PaymentProcessor.class);\\n        \\n        processor.charge(payload.amount());\\n    }\\n}\"}]},{\"type\":\"heading\",\"attrs\":{\"textAlign\":null,\"level\":2},\"content\":[{\"type\":\"text\",\"text\":\"Contextualized Dependency Lookup\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"Dependency lookup is a similar term in some aspect to the dependency pull, but in CDL, the lookup is from the container that manages the resources, not from the central registry.\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"Let's look at a real-world example to understand CDL. It is like a guest chef working in different kitchens. Instead of bringing their own tools(Dependency Injection) or searching the global market(Dependency pull), the chef relies on the kitchen manager to hand them specific tools to work on.\"}]},{\"type\":\"codeBlock\",\"attrs\":{\"language\":\"java\"},\"content\":[{\"type\":\"text\",\"text\":\"package org.csbyte.cdl;\\n\\n\u002F\u002F The CDL Lifecycle Contract\\ninterface RegionManagedComponent {\\n    void initializeContext(PaymentContainer container);\\n}\\n\\n\u002F\u002F The Context Container Interface\\ninterface PaymentContainer {\\n    Object getSecureResource(String resourceName);\\n}\\n\\n\u002F\u002F Concrete Container managing localized secure infrastructure\\nclass USARegionContainer implements PaymentContainer {\\n    @Override\\n    public Object getSecureResource(String resourceName) {\\n        if (\\\"encryptionKey\\\".equals(resourceName)) {\\n            return \\\"USA-AES-KEY-99X72\\\";\\n        }\\n        throw new IllegalArgumentException(\\\"Resource not found in USA Region: \\\" + resourceName);\\n    }\\n}\\n\\n\u002F\u002F The Provider Dependency\\ninterface CryptoEngine {\\n    String encryptData(String rawData);\\n}\\n\\nclass OpenSSLCryptoEngine implements CryptoEngine {\\n    private final String key;\\n\\n    public OpenSSLCryptoEngine(String key) {\\n        this.key = key;\\n    }\\n\\n    @Override\\n    public String encryptData(String rawData) {\\n        return \\\"[Encrypted with \\\" + key + \\\"]: \\\" + rawData;\\n    }\\n}\\n\\n\u002F\u002F The Renderer equivalent: The component executing business logic\\ninterface PaymentProcessor extends RegionManagedComponent {\\n    void processTransaction(double amount);\\n}\\n\\nclass CreditCardProcessor implements PaymentProcessor {\\n    private CryptoEngine cryptoEngine;\\n\\n    \u002F\u002F CDL Implementation: The component waits to be handed the container context\\n    @Override\\n    public void initializeContext(PaymentContainer container) {\\n        \u002F\u002F Look up the exact localized resource using the container provided at initialization\\n        String regionalKey = (String) container.getSecureResource(\\\"encryptionKey\\\");\\n        this.cryptoEngine = new OpenSSLCryptoEngine(regionalKey);\\n    }\\n\\n    @Override\\n    public void processTransaction(double amount) {\\n        if (cryptoEngine == null) {\\n            throw new IllegalStateException(\\\"Processor uninitialized! Context must be loaded first.\\\");\\n        }\\n        String securePayload = cryptoEngine.encryptData(\\\"Card: 4111xxxx; Amount: $\\\" + amount);\\n        System.out.println(\\\"Dispatching transaction payload: \\\" + securePayload);\\n    }\\n}\\n\\npublic class BillingSystemDemo {\\n    public static void main(String... args) {\\n        \u002F\u002F Initialize the local container infrastructure\\n        PaymentContainer usaContainer = new USARegionContainer();\\n\\n        \u002F\u002F Instantiate the component (currently completely detached and empty)\\n        PaymentProcessor processor = new CreditCardProcessor();\\n\\n        \u002F\u002F Contextualization: Hand the local region infrastructure container to the component\\n        processor.initializeContext(usaContainer);\\n\\n        \u002F\u002F Execute business method safely\\n        processor.processTransaction(250.75);\\n    }\\n}\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"Instantiation:\"}]},{\"type\":\"codeBlock\",\"attrs\":{\"language\":\"java\"},\"content\":[{\"type\":\"text\",\"text\":\"PaymentProcessor processor = new CreditCardProcessor();\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"When CreditCardProcessor is created, its internal cryptoEngine field is null\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"Contextualization (The Inversion of Control):\"}]},{\"type\":\"codeBlock\",\"attrs\":{\"language\":\"java\"},\"content\":[{\"type\":\"text\",\"text\":\"processor.initializeContext(usaContainer);\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"Instead of the CreditCardProcessor using a global system setting, it actively hands the localized context container (usaContainer) to the component.\"}]},{\"type\":\"bulletList\",\"content\":[{\"type\":\"listItem\",\"content\":[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"The Component Shows Up Empty: The component (our chef) is created with absolutely nothing inside it. It doesn’t have its tools, and it doesn't try to look for them yet.\"}]}]},{\"type\":\"listItem\",\"content\":[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"The Container Hands Over the Context: The framework (the kitchen manager) actively approaches the component and hands it a specific container context (the workspace box).\"}]}]},{\"type\":\"listItem\",\"content\":[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"The Component Looks Up What it Needs: Now that the component is holding the box, it reaches inside and looks up the exact tools it needs for that specific environment.\"}]}]}]},{\"type\":\"heading\",\"attrs\":{\"textAlign\":null,\"level\":3},\"content\":[{\"type\":\"text\",\"text\":\"When is Contextualized Dependency Lookup actually useful?\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"It is useful when the same component needs to behave differently depending on where or when it is running\"}]},{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"If you hand the component for the US region, it looks inside, pulls out a US encryption key, and processes American dollars. If you hand that exact same component for the Europe region, it looks inside, pulls out a European encryption key, and processes Euros.\"}]}]}","\u002Fuploads\u002Fthumbnails\u002Fd1132443-313b-4dce-b713-55f356ef6051_depndency_pull.png",[11,12,13,14,15,16],"coding","spring-boot","ioc","programming","spring","di",[18,19],"Spring Framework","Spring Boot",[15,12],"2026-05-20T15:26:06.494Z",[23,30,36,42,48,54,60,66,72,77,83,89,95],{"alias":24,"title":25,"description":26,"thumbnail":27,"createdAt":28,"tutorialAlias":29,"lessonAlias":29},"springdoc-openapi-swagger-ui-in-spring","Implementing springdoc-openapi swagger ui in Spring Boot application","Adding springdoc-openapi swagger ui in a Spring Boot application","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002F3501ace5-c9b0-4819-8d35-d8714390c075_swagger_product_highlighted.png","2026-06-30T10:39:32.703Z",null,{"alias":31,"title":32,"description":33,"thumbnail":34,"createdAt":35,"tutorialAlias":29,"lessonAlias":29},"spring-boot-multi-stage-build-with-docker","Creating spring boot multi-stage build with docker","How to create a Spring Boot multi-stage build with Docker","\u002Fuploads\u002Fthumbnails\u002F8931e2f7-a669-4fbb-855b-5ebe396f462e_multi-stage-build-docke.jpeg","2026-06-20T06:34:41.356Z",{"alias":37,"title":38,"description":39,"thumbnail":40,"createdAt":41,"tutorialAlias":29,"lessonAlias":29},"configure-profile-in-spring-boot","Configure different spring profiles in spring boot application","Managing Spring Boot profiles for different environments along with Docker","\u002Fuploads\u002Fthumbnails\u002F59a52e59-4b56-469d-8902-41af5e0f13dd_Spring-profil.jpeg","2026-06-20T04:51:27.098Z",{"alias":43,"title":44,"description":45,"thumbnail":46,"createdAt":47,"tutorialAlias":29,"lessonAlias":29},"global-exception-handling-in-spring-boot","Implementing Robust Global Exception Handling in Spring Boot","How to Handle Errors in Spring Boot: An Architectural Guide","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002F554489e1-d142-4ea5-a393-994a13d7b113_exception-handling.png","2026-06-12T17:15:16.253Z",{"alias":49,"title":50,"description":51,"thumbnail":52,"createdAt":53,"tutorialAlias":29,"lessonAlias":29},"spring-boot-create-libraries-gradle","Building Reusable Spring Boot Libraries with Gradle","Architectural Guide: Building Reusable Spring Boot Libraries with Gradle","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002Ff4fb088d-1018-4d2b-ae6c-cdd5d0fd60ae_spring-Initializr.png","2026-06-12T15:55:20.994Z",{"alias":55,"title":56,"description":57,"thumbnail":58,"createdAt":59,"tutorialAlias":29,"lessonAlias":29},"multi-build-project-gradle-spring-boot","Setting up a multi-project build in Gradle for Spring Boot","How to set up a multi-project build in Gradle for Spring Boot","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002Fd43933e4-a7a3-404b-a300-8f02db98f549_multi-build-project.png","2026-06-12T04:15:23.045Z",{"alias":61,"title":62,"description":63,"thumbnail":64,"createdAt":65,"tutorialAlias":29,"lessonAlias":29},"java-version-mismatch-gradle","Java Version Mismatch for Gradle Build","How to Fix Gradle Error: Dependency requires at least JVM runtime version 17. This build uses a Java 8 JVM","\u002Fuploads\u002Fthumbnails\u002Fa4c6c910-5623-4db9-93f5-a515135adb99_gradle_version_mismatc.jpeg","2026-06-09T12:15:21.729Z",{"alias":67,"title":68,"description":69,"thumbnail":70,"createdAt":71,"tutorialAlias":29,"lessonAlias":29},"constructor-confusion-in-spring","Constructor Confusion in Spring Framework","Constructor Confusion and how to handle it in Spring Framework","\u002Fuploads\u002Fthumbnails\u002Fd0f09fc0-e1f9-49d1-bf9a-7d1c41050196_di_confusio.jpeg","2026-05-21T14:13:31.437Z",{"alias":73,"title":74,"description":74,"thumbnail":75,"createdAt":76,"tutorialAlias":29,"lessonAlias":29},"types-of-dependency-injection-spring","Types of Dependency Injection in Spring Framework","\u002Fuploads\u002Fthumbnails\u002Fafb32399-6dda-41c4-b07c-7decb8257bbb_di_constructor_sette.jpeg","2026-05-19T17:01:51.972Z",{"alias":78,"title":79,"description":80,"thumbnail":81,"createdAt":82,"tutorialAlias":29,"lessonAlias":29},"spring-framework-project-for-gradle-with-intellij-idea","How to create a clean Spring Framework project for Gradle with IntelliJ IDEA","Create a clean Spring Framework project for Gradle with IntelliJ IDEA","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002F0e4abad5-17e2-4311-8cf0-7d8f67af975a_spring-framework.png","2026-05-19T10:28:20.866Z",{"alias":84,"title":85,"description":86,"thumbnail":87,"createdAt":88,"tutorialAlias":29,"lessonAlias":29},"spring-dependency-injection-and-inversion-control","Dependency Injection (DI) and Inversion of Control (IoC) in Spring","Mastering Dependency Injection (DI) and Inversion of Control (IoC) in Spring: A Practical Guide for Building a Notification System","\u002Fuploads\u002Fthumbnails\u002F53c64b94-f188-40b4-9ae9-ad97612d688b_spring_d.jpeg","2026-05-19T05:31:45.138Z",{"alias":90,"title":91,"description":92,"thumbnail":93,"createdAt":94,"tutorialAlias":29,"lessonAlias":29},"setting-nginx-ssl-for-spring-boot-application","Setup Nginx and SSL for Spring Boot Application","Setting Nginx as a reverse proxy in our Spring Boot application","\u002Fuploads\u002Fthumbnails\u002F5433c987-9e86-4d90-9cce-a831d1598ba4_spring-boot-nginx.png","2026-05-04T05:36:23.075Z",{"alias":96,"title":97,"description":98,"thumbnail":99,"createdAt":100,"tutorialAlias":29,"lessonAlias":29},"deploy-spring-boot-application-with-docker","Deploy Spring Boot Application with Docker on Ubuntu Server","The ultimate guide to deploying our Spring Boot application with Docker on an Ubuntu server","https:\u002F\u002Fapi.csbyte.com\u002Fuploads\u002Feditor\u002F55a11844-d1e9-4e83-80e5-c6bb6df7d58b_intellij-idea-build.png","2026-05-03T05:58:55.642Z"]