TIL about Spring’s @ExceptionHandler selection rules — and it surprised me a bit. Quick summary: Inside the same @ControllerAdvice: root exception match > cause match Across different advice beans: @Order priority beats everything — even root vs cause. So a higher-priority advice matching a cause can override a lower-priority advice matching the actual exception. Lesson learned: Put your primary/global exception handlers in a high-priority @ControllerAdvice. Sharing in case it saves someone else a debugging session 🙂 #SpringBoot #Java
Spring Exception Handling Rules for @ControllerAdvice
More Relevant Posts
-
Have you ever wondered how Spring Boot injects dependencies ? “Spring injects dependencies automatically.” But very few can explain HOW. Here’s what really happens behind the scenes: 1- Spring scans your classes 2- It creates BeanDefinitions 3- The ApplicationContext instantiates beans 4- Dependencies are resolved via constructor/setter injection 5- Beans go through the full lifecycle (init → post-processors → ready) Dependency Injection is not magic. It’s a container managing object graphs for you. If you understand: • Bean lifecycle • Singleton vs prototype scope • BeanPostProcessor • ApplicationContext vs BeanFactory You’re already thinking beyond annotations. I just broke it all down step by step https://lnkd.in/ewNmUK5b #SpringBoot #SpringFramework #Java #BackendDevelopment #SoftwareArchitecture
To view or add a comment, sign in
-
Day 22/30 – Remove Nth Node From End of List Solved a classic Linked List problem today. Approach: • Use Two Pointers (Fast & Slow) • Move fast pointer n+1 steps ahead • Move both pointers until fast reaches the end • Slow pointer will be right before the node to remove Time Complexity: O(n) Space Complexity: O(1) Key concept: Two-pointer technique with a dummy node. #30DaysOfDSA #Java #LinkedList #CodingChallenge
To view or add a comment, sign in
-
-
Day 30 — LeetCode Progress (Java) Rotate Array Required: Rotate the array to the right by k steps efficiently without using extra space. Idea: Instead of shifting elements one by one, use array reversal to reposition elements in optimal order. Approach: Reverse the entire array Reverse first k elements Reverse remaining elements Time Complexity: O(n) Space Complexity: O(1) #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Spring Boot dependency injection (DI) pitfalls I learned building my first REST API: Don't rely on field injection blindly-use constructors for immutability and testability. Scenario: Multiple beans of the same type? @Qualifier saves the day. @Autowired @Qualifier('taskServiceImpl') private TaskService taskService; Pro tip: @Configuration + @Bean for custom wiring. Deployed my task manager CRUD in 20 mins-zero null pointers. Reduced boilerplate by 60%. Try it on your next project! Thoughts? #SpringBoot #Java #BackendDev
To view or add a comment, sign in
-
-
🔥 DAY 2 **How Spring Boot Dependency Injection actually works (Simple explanation)** Most developers use @Autowired. Few understand what happens behind the scenes. Here’s what Spring does: • Scans components • Creates beans in ApplicationContext • Manages lifecycle • Injects dependencies via constructor/setter Why it matters? Because: * It improves testability * Reduces tight coupling * Makes large systems manageable Framework knowledge is good. Understanding internals is better. #SpringBoot #Java #BackendDevelopment
To view or add a comment, sign in
-
Day 35 - Min Stack Designed a stack that supports push, pop, top, and retrieving the minimum element in constant time. Used an auxiliary stack to track the minimum value at each stage, ensuring efficient updates during push and pop operations. Time Complexity: O(1) for all operations #Day35 #LeetCode #Java #Stack #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 37 - Implement Queue using Stacks Implemented a FIFO queue using two stacks while supporting operations like push, pop, peek, and empty. Used one stack for input and another for output. Elements are transferred only when needed to maintain the correct order. Time Complexity: Amortized O(1) #Day37 #LeetCode #Java #Stack #Queue #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Spent 3 hours debugging a null pointer exception yesterday. Turned out the problem was one line: user.getAddress().getCity().toUpperCase() If address is null, it blows up. If city is null, it blows up. The fix took 10 seconds: Optional.ofNullable(user.getAddress()) .map(Address::getCity) .map(String::toUpperCase) .orElse("N/A") I mass is forget how many production bugs come from chained method calls. Nulls are sneaky. Optional makes them visible. Anyone else mass is this mistake more than once? #Java #SpringBoot #Debugging #BackendDevelopment
To view or add a comment, sign in
-
Day 38 — LeetCode Progress (Java) Problem: Successful Pairs of Spells and Potions Required: For each spell, find how many potions form a successful pair such that spell × potion ≥ success. Idea: Sort the potions array so binary search can be used to find the first valid potion that satisfies the condition. Approach: Sort the potions array. For each spell, perform binary search on potions. Find the smallest index where spell × potion ≥ success. All potions to the right of that index form valid pairs. Store the count in the result array. Time Complexity: O(n log m) Space Complexity: O(1) (excluding output array) #LeetCode #DSA #Java #BinarySearch #Arrays #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 14- What I Learned in a Day(JAVA) Concatenation Operator :("+") • Used to combine two or more strings • Commonly used to join text with variables • Helps in displaying meaningful output messages Increment Operator: • Used to increase a variable value by one • Can be used in pre-increment(++varname) and post-increment(varname ++) form Decrement Operator: • Used to decrease a variable value by one • Can be used in pre-decrement(--varname) and post-decrement(varname--) form. 🔹 I practiced small programs to understand how these operators behave during execution and how output changes based on their usage. Practiced 👇 #Java #JavaProgramming #OperatorsInJava #CodingPractice #LearningJourney #ProgrammingLife #TechSkills #FutureDeveloper 🚀
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