Ever noticed how one small backend concept can quietly make your entire application more reliable? 💡 Today I explored something powerful in Spring Boot — "OncePerRequestFilter". At first, it looks like just another filter. But when you start building real-world applications with JWT authentication, request logging, security checks, and tracing, this class becomes a game changer. The best part? It ensures your filter logic runs only once for every HTTP request. Sounds simple, right? But imagine a production system where the same request gets internally forwarded and your filter executes multiple times. That could mean: 🔁 repeated token validation 📝 duplicate logs ⚠️ unnecessary processing 🐢 slower performance This is where "OncePerRequestFilter" saves the day. It brings consistency, security, and cleaner request flow to your application. One of the most common use cases is in JWT authentication: ➡️ Read token from header ➡️ Validate it ➡️ Authenticate user ➡️ Set security context ➡️ Pass request forward And all of this happens exactly once. For me, this is one of those concepts that proves: Great backend engineering is often about controlling what should happen once — and only once. Small concept. Big impact. 🚀 Backend developers, where have you used "OncePerRequestFilter" in your projects? Would love to learn your real-world use cases in the comments 👇 #Java #SpringBoot #SpringSecurity #BackendDevelopment #JavaDeveloper #SoftwareEngineering #CodingJourney #TechLearning #JWT #WebDevelopment #Programming #Developers #unique2
OncePerRequestFilter boosts Spring Boot application reliability
More Relevant Posts
-
🚀 𝟭𝟬 𝗦𝗽𝗿𝗶𝗻𝗴 𝗔𝗻𝗻𝗼𝘁𝗮𝘁𝗶𝗼𝗻𝘀 𝗘𝘃𝗲𝗿𝘆 𝗝𝗮𝘃𝗮 𝗗𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿 𝗦𝗵𝗼𝘂𝗹𝗱 𝗠𝗮𝘀𝘁𝗲𝗿 𝗠𝗼𝘀𝘁 𝗱𝗲𝘃𝗲𝗹𝗼𝗽𝗲𝗿𝘀 𝘀𝘁𝗼𝗽 𝗮𝘁: ✔ @RestController ✔ @Service ✔ @Autowired But Spring becomes truly powerful when you move beyond the basics. Some annotations that make a real difference in production apps 👇 𝗖𝗼𝗻𝗳𝗶𝗴𝘂𝗿𝗮𝘁𝗶𝗼𝗻 & 𝗕𝗲𝗮𝗻 𝗖𝗼𝗻𝘁𝗿𝗼𝗹 @Configuration, @Bean, and @ConfigurationProperties help keep configuration clean, type-safe, and scalable. 𝗔𝗣𝗜 & 𝗩𝗮𝗹𝗶𝗱𝗮𝘁𝗶𝗼𝗻 @ControllerAdvice, @Valid, and @RequestParam reduce boilerplate and make APIs easier to maintain. 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 & 𝗦𝗮𝗳𝗲𝘁𝘆 @Async, @Transactional, and @Cacheable improve responsiveness, consistency, and speed. 𝗔𝗱𝘃𝗮𝗻𝗰𝗲𝗱 𝗗𝗲𝘀𝗶𝗴𝗻 @EventListener helps build decoupled workflows, while @Profile makes environment-based behavior clean and safe. The real power of Spring annotations is not convenience. It’s how they make design decisions explicit in your code. 𝗢𝗻𝗰𝗲 𝘆𝗼𝘂 𝘀𝘁𝗮𝗿𝘁 𝘂𝘀𝗶𝗻𝗴 𝘁𝗵𝗲 𝗿𝗶𝗴𝗵𝘁 𝗮𝗻𝗻𝗼𝘁𝗮𝘁𝗶𝗼𝗻𝘀, 𝘆𝗼𝘂𝗿 𝗮𝗽𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗯𝗲𝗰𝗼𝗺𝗲𝘀: ✔ cleaner ✔ safer ✔ easier to scale Which Spring annotation changed the way you build Java applications? #SpringBoot #Java #SpringFramework #JavaDeveloper #BackendDevelopment
To view or add a comment, sign in
-
🔥 Why Your Spring Boot App Returns 404 Even After Successful Startup ⸻ 1. Verify Controller Registration (Not Just Scanning) ➡️ Run with --debug and check auto-configuration logs ➡️ Use /actuator/mappings to confirm if endpoints are actually exposed ⚠️ If your endpoint is NOT listed → it’s not a routing problem, it’s a bean registration issue ⸻ 2. Package Structure (Classic Mistake) Spring Boot only scans downward from the main class package ✔️ Correct: com.app ├── Application.java ├── controller ❌ Wrong: com.app com.controller (won’t be scanned) ➡️ Fix with @ComponentScan if needed ⸻ 3. Annotation Issues (Very Common) ➡️ Missing @RestController or @Controller ➡️ Missing @RequestMapping, @GetMapping, etc. ➡️ Using @Controller without @ResponseBody → returns view instead of JSON → looks like 404 ⸻ 4. Context Path / Port Confusion Check: server.servlet.context-path=/api server.port=8081 Your endpoint becomes http://localhost:8081/api/hello ⚠️ Many devs hit /hello → get 404 → panic 😄 ⸻ 5. Spring Security Blocking Requests ➡️ If Spring Security is enabled: * Unauthenticated requests may not reach controller * Misconfigured rules can return 404 instead of 403 ✔️ Temporarily disable or allow all: http.authorizeHttpRequests().anyRequest().permitAll(); 6. DispatcherServlet Not Mapping Requests ➡️ Check if: spring.mvc.servlet.path Or custom servlet config is changing the routing 7. Static Resource Handler Overriding APIs ➡️ If WebMvcConfigurer is customized, static handlers might override API paths ⸻ 8. Wrong HTTP Method ➡️ Calling GET /users but API is @PostMapping("/users") ➡️ Spring returns 404 (not always 405 depending on config) ⸻ 9. Reverse Proxy / Gateway Issues (Production Case) ➡️ If behind: * Nginx * API Gateway Check if path rewriting is happening: /api/users → /users 10. Build / Deployment Mismatch ➡️ Old JAR running? ➡️ Controller added but not redeployed? ✔️ Always verify: ps -ef | grep java #engineering #development #springboot #java
To view or add a comment, sign in
-
Understanding CORS Errors (Simple Analogy) While working on backend APIs, I often faced CORS errors. It’s confusing at first because api works fine still we face issue, but simple when you relate it to real life. Think of your frontend and backend as two buildings, and the browser as security. You can access your own building freely, but entering another requires permission. Similarly, when your frontend (React/Angular) calls an API from a different origin (domain, port, or protocol), the browser blocks it unless the backend allows it. That’s where CORS configuration comes in. By adding allowed origins (e.g in Spring Boot), you’re telling the browser: This frontend is trusted. Without this: * Requests fail even if the API works fine * Errors appear in the browser, not backend logs Key learning: CORS is not a backend error — it’s a browser security feature. Understanding this helped me debug issues faster and avoid unnecessary backend changes. #SpringBoot #CORS #BackendDevelopment #WebDevelopment #WebSecurity #Java #APIs #FullStackDevelopment
To view or add a comment, sign in
-
-
Most people think setting up a Spring project is just generating code and getting started. It’s not. The way you set up your project on day one directly impacts how easy (or painful) development becomes later. Here’s the simple process I follow every time I start a Spring project: First, I get clarity on what I’m building. Is it a REST API, a full-stack app, or a microservice? Do I need a database? Security? Docker? Spending 5–10 minutes thinking here saves hours later. Then I use Spring Initializr to bootstrap the project. I keep it minimal — only the dependencies I actually need: Spring Web, JPA, maybe Security, Lombok, and a database driver. No overengineering at the start. Next comes structure. I follow a clean layered approach: Controller → Service → Repository → Entity → DTO This keeps things organized and avoids chaos as the project grows. After that, I configure the basics: – application.properties (or yml) – database connection – server port – logging I also make sure to separate configs for dev and prod early. Once the setup is ready, I connect the database: – Create entities – Define repositories – Run a few test queries Catching issues here is much easier than debugging later. I always add: – Global exception handling – Input validation – Proper logging These things seem small, but they make your app production-ready. Finally, I test early. Even a few API calls using Postman or Swagger help validate everything is wired correctly. A solid Spring setup doesn’t take long. But if you skip these basics, you’ll pay for it later in debugging, refactoring, and messy code. Build it right from the start. #SpringBoot #Java #BackendDevelopment #SoftwareEngineering #CleanCode #Microservices #Developers #Tech #Programming #Coding
To view or add a comment, sign in
-
-
💡 Thread pools were a nightmare. I’m glad they’re finally dying. I used to spend way too much time obsessing over thread pool tuning. Seriously. Calculating the "perfect" number of threads to stop a Spring Boot app from falling over under heavy I/O felt like a dark art. If you haven't had a minor panic attack over a ThreadPoolExecutor rejection policy at 4 PM on a Friday... have you even done backend dev? But honestly? That era is ending. Lately, I’ve been stripping out that complexity. By just toggling spring.threads.virtual.enabled=true in my Spring Boot 3.x builds, the whole "thread-per-request" bottleneck just... vanishes. It’s weird how simple it feels. Why I’m actually excited about this (and why you should be too): No more "Callback Hell": I’m done with the mental gymnastics of reactive programming. I want to write code that I can actually read. Sequential, clean, and simple. RAM that doesn't quit: Handling massive concurrent loads without the memory footprint of traditional threads is a lifesaver for cloud costs. Actually debuggable: Have you ever tried to trace a reactive stream? It's a mess. Debugging a virtual thread stack trace actually makes sense. The most impactful move I’ve made this year wasn't building something more complex. It was making my stack simpler so the JVM does the heavy lifting. Java is in a new golden age—if you’re still stuck in the Java 8/11/17 mindset, you’re missing the best part of the job. 👉 Are you still babysitting thread pools? Or have you moved to Virtual Threads yet? #Java26 #SpringBoot3 #SpringBoot4 #ProjectLoom #Backend #SoftwareEngineering #CloudComputing #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 What is Spring Initializr? Starting a Spring Boot project from scratch can be time-consuming… unless you use Spring Initializr 👇 🔹 Generate a ready-to-run project in seconds 🔹 Choose dependencies (Web, JPA, Security, etc.) 🔹 Get pre-configured structure & build files 🔹 Works with Maven or Gradle 💡 No setup hassle—just generate, download, and start coding. If you're building Java backend apps, this tool is a must-have! #SpringBoot #Java #BackendDevelopment #SoftwareEngineering #Microservices #Developers
To view or add a comment, sign in
-
-
Circular dependencies in Spring Boot can quietly break your app at startup. When DepositService depends on PaymentService and PaymentService depends back on DepositService, Spring Boot 2.6+ will fail with BeanCurrentlyInCreationException. That’s because circular dependencies are now prohibited by default. Why it fails Spring can’t fully create either bean because each one needs the other first. This creates a startup deadlock instead of a clean dependency graph. Best fix Refactor the design. Move shared logic into a third service so the dependency flow becomes one-way, not circular. This is the most maintainable solution. Other options Use @Lazy to inject a proxy and delay bean creation. Use setter injection as a last resort when you must break the creation cycle. Takeaway If you hit a circular dependency, treat it as a design smell, not just a Spring error. Fix the architecture first, and only use framework-level workarounds when absolutely necessary. #SpringBoot #Java #SpringFramework #BackendDevelopment #SoftwareEngineering #TechTips #Programming #CleanCode #Microservices #SoftwareDeveloper #TechCommunity #DeveloperTools #CircularDependency #DependencyInjection #LinkedInTech #Coding #Debugging #SystemDesign #C2C #C2CJobs #C2CRecruiting #C2CContract #ContractJobs #ITRecruitment #TechHiring #USJobs #JobSearch #HiringNow
To view or add a comment, sign in
-
-
🚀 Spring Framework Deep Dive – Day 18 🚨 Your Spring Boot app crashed in production. No alerts. No warnings. No idea why. You know what was missing? Logging. I've seen developers spend HOURS debugging... when proper logging would have shown the answer in SECONDS. Here's everything you need to know 👇 🔹 What is Logging? → Recording everything that happens inside your app → Helps debug issues in seconds not hours → Tracks user actions and system behavior → Non-negotiable in production applications 🔹 Spring Boot uses SLF4J + Logback by default → Zero setup needed ✔ → Just inject the logger and start logging 🔹 5 Log Levels you MUST know: 🔵 TRACE → Every single step (dev only) 🟢 DEBUG → Detailed debugging info 🟡 INFO → General events (default) ⭐ 🟠 WARN → Something might go wrong 🔴 ERROR → Something broke — fix NOW 🚀 Real-world example: Banking app 🏦 👉 INFO — "User John logged in successfully" 👉 WARN — "Login failed 3 times for John" 👉 ERROR — "Payment service not responding" 👉 DEBUG — "Processing transaction ID: 10234" 🔥 The hard truth: Without logging — you are flying blind in production. With logging — you know EXACTLY what happened and when. 💡 Simple way to remember: TRACE → DEBUG → INFO → WARN → ERROR Least detail →→→→→→→→ Most critical Logging + Exception Handling = Rock-solid production app 🚀 More deep dives coming 🚀 💬 Have you ever spent hours debugging something that logging would have solved in seconds? Drop your story 👇 #SpringBoot #JavaDeveloper #BackendDevelopment #Logging #FullStackDeveloper #OpenToWork #Java #100DaysOfCode
To view or add a comment, sign in
-
-
Why Most Backend Systems Become Hard to Maintain After a few years working with Java and Spring Boot, I noticed a common pattern. Systems don’t become complex overnight. They slowly grow into it. At the beginning, everything is simple. Small classes, clear logic, fast development. Then over time: - New features are added without refactoring - Business logic starts spreading across multiple layers - Quick fixes become permanent solutions - Classes grow too large and hard to understand - Dependencies between modules become messy And suddenly, even a small change feels risky. Some lessons I learned: - If it’s hard to change, it’s badly designed - Refactoring is not optional, it’s part of development - Clear boundaries between modules make a big difference - Naming matters more than we think - Technical debt always comes back with interest Building a system is one thing. Keeping it clean over time is the real challenge. For backend developers, what made your system hard to maintain? #Java #SpringBoot #SoftwareEngineering #BackendDevelopment #CleanCode #Refactoring #SystemDesign #Microservices
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