🧠 After exploring singleton and prototype, I discovered a very practical Spring Boot scope today 👀 Request Scope 🌐 Here’s the simple idea 👇 ✅ A new bean object is created for every HTTP request ✅ Different requests never share the same object ✅ Perfect for request-specific processing This makes it super useful for 👇 🔹 request tracing IDs 🔹 temporary request metadata 🔹 audit logging helpers 🔹 request-level user context The cleanest way to use it 👇 @RequestScope 💡 My takeaway: Scope is not just about memory — it directly shapes how safely your web app handles request data ⚡ #Java #SpringBoot #RequestScope #BackendDevelopment #LearningInPublic
Aditya Solanki’s Post
More Relevant Posts
-
🚀 Day 18/100: Spring Boot From Zero to Production Topic: Auto-Configuration 💡 What is Auto-Configuration? One of the most powerful features in Spring Boot Turns hours of setup into minutes Eliminates heavy XML configs and manual bean wiring ⏳ Before Auto-Configuration Manually define multiple beans Write hundreds of lines of XML Configure everything yourself → painful ⚙️ What Happens Now? Your @SpringBootApplication kicks things off Spring Boot scans the classpath Looks for dependencies like: spring-webmvc spring-data-jpa 👉 Presence/absence of JARs = signals 🧠 Behind the Scenes Reads a special file: META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports Contains hundreds of auto-config classes Each uses conditions like: @ConditionalOnClass @ConditionalOnMissingBean 👉 Result: Beans get configured automatically 🌐 Simple Example Add: spring-boot-starter-web Spring Boot assumes: You need a web app So it adds an embedded server (Tomcat) automatically 🛠️ Can You Override It? YES You can: Define your own beans Override defaults Disable auto-config if needed Auto-configuration isn’t magic. It’s just smart defaults + conditional logic working for you #Java #SpringBoot #SoftwareDevelopment #100DaysOfCode #Backend
To view or add a comment, sign in
-
-
𝗦𝘁𝗼𝗽 𝘂𝘀𝗶𝗻𝗴 @ComponentScan 𝗳𝗼𝗿 𝘀𝗵𝗮𝗿𝗲𝗱 𝗺𝗼𝗱𝘂𝗹𝗲𝘀.⚡️ Your shared libraries should be 𝗽𝗹𝘂𝗴-𝗮𝗻𝗱-𝗽𝗹𝗮𝘆, not a guessing game of which beans are being scanned. 👉 The fix? 𝗔𝘂𝘁𝗼-𝗰𝗼𝗻𝗳𝗶𝗴𝘂𝗿𝗮𝘁𝗶𝗼𝗻. Clean. Predictable. Zero setup. I wrote a quick guide on how to do it right in Spring Boot 👇 https://lnkd.in/dAu6mrtG #SpringBoot #Beans #Java #Kotlin #SoftwareArchitecture
To view or add a comment, sign in
-
🧠 After learning Dependency Injection, I had one big question 👀 Who actually creates these objects in Spring Boot, and when? Today I explored the Spring Bean Lifecycle 🚀 Simple flow 👇 1️⃣ Spring container starts 2️⃣ Bean object is created 3️⃣ Dependencies are injected 4️⃣ Bean becomes ready to use 5️⃣ Bean is destroyed when the app shuts down What made this even more interesting 👇 ✅ @PostConstruct → runs after bean creation ✅ @PreDestroy → runs before bean cleanup 💡 My takeaway: Spring doesn’t just inject dependencies — it also manages the entire lifecycle of the object. The more I learn this framework, the more beautifully engineered it feels ⚡ #Java #SpringBoot #BeanLifecycle #BackendDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
Spring Boot Interview Series — Post 9 Spring Boot fails to start when two beans depend on each other. BeanCurrentlyInCreationException - Spring tries to create DepositService, which needs PaymentService, which needs DepositService and it's stuck. From Spring Boot 2.6, circular dependencies are prohibited by default. Your app fails at startup - no silent failures. 3 ways to fix it - in order of preference: -> Refactor - circular dependency is a design smell. It usually means two classes are doing too much. Extract the shared logic into a third service. DepositService → NotificationService, PaymentService → NotificationService. No cycle. Clean design. -> @Lazy - put it on the constructor parameter of one bean. Spring injects a proxy placeholder instead of the real bean. The real bean is created only when first used. Quick fix - but doesn't solve the underlying design problem. Use only when refactoring is not practical. -> Setter injection - Spring creates both beans first, then injects dependencies via setters. Breaks the creation deadlock. Field cannot be final. Last resort only. Circular dependency is almost always a sign that two classes are too tightly coupled. Fix the design before reaching for @Lazy. #SpringBoot #Java #JavaDeveloper #BackendDevelopment #SpringFramework
To view or add a comment, sign in
-
-
Spring Boot Bean Lifecycle — Most developers ignore this 🔥 Do you know what happens before your bean is ready? Here’s the flow 👇 1️⃣ Bean Instantiation 2️⃣ Dependency Injection 3️⃣ @PostConstruct runs 4️⃣ Bean is ready to use ✅ And before shutdown: 👉 @PreDestroy is called 💡 Why it matters: ✔ Resource initialization ✔ Cleanup logic ✔ Better control over application lifecycle ⚠️ Mistake: Putting heavy logic inside constructors ❌ 👉 Use @PostConstruct instead Understanding lifecycle = writing smarter Spring Boot apps 🚀 #SpringBoot #Java #BackendDeveloper
To view or add a comment, sign in
-
Understanding HTTP Status Codes Today I focused on an important concept in backend development — HTTP Status Codes While building REST APIs, it’s not just about sending data, but also about sending the right response to the client. 🔹 Learned about different categories of status codes: • 2xx (Success) – 200 OK, 201 Created • 4xx (Client Errors) – 400 Bad Request, 404 Not Found • 5xx (Server Errors) – 500 Internal Server Error 🔹 Understood when to use each status code in real APIs 🔹 Implemented status handling using "ResponseEntity" in Spring Boot This helped me realize how APIs communicate clearly with frontend applications and handle errors properly. Small concept, but very powerful in building real-world applications. Next step: Improving API structure and adding more real-world logic. #Java #SpringBoot #BackendDevelopment #RESTAPI #CodingJourney
To view or add a comment, sign in
-
Excited to be part of this Real-Time Patient Monitoring System project! This implementation demonstrates how low-level TCP socket communication can be effectively integrated with a Java backend and multiple client interfaces, ensuring real-time data synchronization across both web and terminal environments. A great experience working on system design, networking, and handling real-time data streams alongside an amazing team. Feel free to explore the project and share your feedback. #Networking #TCP #SocketProgramming #JavaDevelopment #ReactJS #EngineeringProjects
Undergraduate BSc (Hons) Computer Engineering | Full Stack Developer | UI/UX | Web Designer | Faculty of Engineering | University of Ruhuna
⚡ What happens when you combine real-time TCP sockets, a solid Java backend, and two completely different ways to interact with them? ⬇️ 🏥 Check out our team's latest project! We built a Real-Time Patient Monitoring System designed for ultimate flexibility: accessible via a sleek React Web Dashboard or directly through the Command Line Terminal . 🎥 In this video, you can see both interfaces running in parallel. Here is a look under the hood of our architecture : 🔹 Dual Interfaces: We built the Web and Terminal clients completely separately to ensure decoupling and clean code. 🔹 Real-Time Networking: Both clients communicate seamlessly with our Java backend using low-level TCP Sockets. 🔹 Heavy Lifting on the Client: The web version doesn't just display static data—it actively manages real-time socket streams to keep patient vitals and documents instantly updated, mirroring the exact networking logic of the terminal version. 🧠 Getting this architecture right took a lot of complex problem-solving and late nights . I couldn't have asked for a better crew to build this with. Extremely proud of the hard work put in by Piyumi Sandunika, Emasha Chathuni Medakanda, Hasith Heshika, and Sitharaka Jayawardhana to bring this to life! 👏 Want to dive into the code or try running both clients yourself? Check out our repository here: 🔗 https://lnkd.in/g3t2P8cs Would love to hear your thoughts or feedback in the comments! 👇 #Networking #TCP #SocketProgramming #TechProjects #FullStack #ReactJS #JavaDevelopment #EngineeringTeam #ProjectShowcase
To view or add a comment, sign in
-
🚨 Why I stopped using field injection in Spring Boot I used to write this: @Autowired private UserService userService; Looks clean… but caused real issues. ❌ Problems: * Hard to test * Hidden dependencies * NullPointer risks in edge cases ✅ Now I always use constructor injection: public UserController(UserService userService) { this.userService = userService; } 💥 Real benefit: While writing unit tests, I realized I could mock dependencies easily without Spring context. 💡 Takeaway: Field injection is convenient. Constructor injection is production-safe. Small change. Big impact. #Java #SpringBoot #BackendDevelopment #SoftwareEngineering #Microservices #RESTAPI #SystemDesign #DeveloperLife #100DaysOfCode
To view or add a comment, sign in
-
🚀 What really happens when you run a Spring Boot application? Most developers use: 👉 SpringApplication.run(App.class, args); …but few understand what happens behind the scenes. Here’s a clear breakdown: 🔹 1. Bootstrapping Starts The JVM calls main(), and Spring Boot begins initialization. 🔹 2. Environment Setup Loads application.properties / application.yml, environment variables, and profiles. 🔹 3. ApplicationContext Creation Spring creates the IoC container to manage all beans. 🔹 4. Component Scanning Detects @Component, @Service, @Repository, @RestController and registers them. 🔹 5. Auto-Configuration Based on dependencies, Spring Boot configures components automatically (MVC, JPA, etc.). 🔹 6. Embedded Server Startup Starts embedded Apache Tomcat—no external installation needed. 🔹 7. DispatcherServlet Initialization Registers the front controller to handle all incoming HTTP requests. 🔹 8. Bean Initialization & Dependency Injection All beans are created and wired using DI. 🔹 9. Application Ready ✅ Your app is now ready to handle requests. 💡 Key Takeaway: SpringApplication.run() is not just a method—it bootstraps the entire application, sets up the container, auto-configures components, and starts the web server. #Java #SpringBoot #BackendDevelopment #Microservices #Programming #SoftwareEngineering #TechLearning
To view or add a comment, sign in
-
-
Spring Boot Bean Scope — Not just Singleton 🤯 Most developers only know this: 👉 Default scope = Singleton But there’s more 👇 ✅ Prototype → New instance every time ✅ Request → Per HTTP request ✅ Session → Per user session 💡 Why it matters: ✔ Memory optimization ✔ Better state handling ⚠️ Mistake: Using singleton for stateful data ❌ 👉 Leads to concurrency issues 🔥 Real lesson: Choose scope based on use case, not default Backend bugs often start here 🚨 #SpringBoot #Java #Architecture
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development