Dev Notes #03 Not every dev note is about something that worked, While building the authentication system, my controller was calling a method that didn't exist in my service layer yet. And what was the fix? Adding the missing method. But here's what was actually worth noting down: In Spring Boot, the Controller handles incoming requests, the Service holds the business logic, and the Repository talks to the database. They're separate layers on purpose, each has one job. When the controller tries to do something the service hasn't defined yet, it breaks. And according to me, that's a good thing since it means your layers are actually separated the way they should be. Who would have though that debugging would be so insightful about architecture. #Java #SpringBoot #BackendDevelopment #Debugging #LearningInPublic
Debugging Spring Boot Layers: Controller, Service, Repository Separation
More Relevant Posts
-
🚀 Daily Update On LibraryManagementProject Finished implementing CRUD operations for the Book resource today 👏 Built endpoints to Create, Fetch, Update, and Delete books, and structured everything with controller -> service -> repository. Also added DTO mapping and basic exception handling to keep responses clean. Ran into couple of issues along the way 😥 ➡️ Method mismatch in the service layer. ➡️ Accidentally calling the update method twice in the controller 😅 ➡️ Git push failed at first because the branch had no upstream Fixed the, pushed successfully, and everything is woking as expected now. Just documenting the process as I go. If you're building something similar, or want to learn three-layer Spring Boot structure, feel free to follow along👍 👍 Next up: Category resource. #SpringBoot #Java #BackendDevelopment #BuildingInPublic 💪
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
-
Spent 10 minutes wondering why my Spring Boot application was not picking up environment variables. The code looked fine: @Value("${DATABASE_URL}") private String databaseUrl; No errors at startup. But the value was always null. The problem: I was using underscores in the property name, but Spring expects dots or lowercase with hyphens. The fix: @Value("${database.url}") private String databaseUrl; And in application_properties: database.url=${DATABASE_URL} One mapping. That was it. Spring does not automatically convert environment variable names to property names. You need to map them explicitly. What environment variable issue has caught you off guard? #Java #SpringBoot #EnvironmentVariables #Debugging #BackendDevelopment
To view or add a comment, sign in
-
💡Spring Autowiring by Type 🔶What is Autowiring by Type? Autowiring by Type allows Spring to identify and inject a bean whose class/type matches the property defined in another class. 🔍 How it Works: Spring scans the property type in the target class It searches for a bean with the same type in the container If exactly one matching bean is found, it gets injected automatically 🧩 Example Concept: If a class has a property of type Computer, Spring will inject a bean of type Computer (like Desktop or Laptop), without considering the bean ID. ✅ Key Benefits: Reduces dependency on naming conventions Minimizes manual configuration Improves code readability and maintainability 🎯 Key Takeaway: Autowiring by Type simplifies dependency management by focusing on what the object is, rather than what it is called, making your Spring applications more flexible and robust. #SpringFramework #Autowiring #DependencyInjection #Java #BackendDevelopment #CleanCode Thanks to Anand Kumar Buddarapu Sir.
To view or add a comment, sign in
-
Spring Boot Filters vs Interceptors — Most developers confuse this 🤯 Let’s simplify 👇 ✅ Filter (Servlet level) - Works BEFORE DispatcherServlet - Used for logging, authentication, request modification ✅ Interceptor (Spring level) - Works AFTER DispatcherServlet - Used for business-level checks 💡 Flow: Request → Filter → DispatcherServlet → Interceptor → Controller ⚡ Real use case: - Filter → JWT validation - Interceptor → role-based access 👉 Choosing wrong = messy architecture Know the difference = cleaner backend 🔥 #SpringBoot #Java #BackendDeveloper
To view or add a comment, sign in
-
🧠 After learning the Spring Bean Lifecycle, I explored another powerful concept today 👀 Singleton vs Prototype Bean Scope in Spring Boot 🚀 The default scope in Spring is singleton 👇 ✅ Only one object instance is created ✅ Shared across the whole application ✅ Best for services, repositories, controllers Then comes prototype 👇 🔁 A new object is created every time it is requested This makes it useful for: ✅ temporary objects ✅ stateful helpers ✅ per-request custom processing 💡 My takeaway: Bean scope directly changes how Spring manages memory and object reuse. Small annotations can completely change runtime behavior ⚡ #Java #SpringBoot #BeanScope #BackendDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
#Post7 In the previous post, we saw how to handle exceptions globally using @ControllerAdvice. Now let’s take it one step further 👇 How do we handle specific errors properly? That’s where Custom Exceptions come in 🔥 Instead of using generic exceptions, we can create our own exception based on the use case. Example: public class UserNotFoundException extends RuntimeException { public UserNotFoundException(String message) { super(message); } } 👉 Now we can throw this exception when user is not found Example usage: if(user == null){ throw new UserNotFoundException("User not found"); } 💡 Why use Custom Exceptions? • Better error clarity • Easy debugging • More control over API responses Key takeaway: Use custom exceptions to make your API errors more meaningful and structured 👍 In the next post, we will understand validation using @Valid 🔥 #Java #SpringBoot #BackendDevelopment #RESTAPI #LearnInPublic
To view or add a comment, sign in
-
Have you ever debugged a production issue where logs show the same error everywhere… but you still can’t figure out what actually failed? I used to make this mistake a lot — catch exception → log error → throw again Service logs Repository logs Controller logs Same exception 3–4 times. Just noise. Then I changed one simple thing: don’t log where you’re just throwing the exception. Now I follow this: Service/Repository → just throw or wrap the exception Log only once at the boundary (API / consumer) Always add context We often don’t pay much attention to logging, but it plays a crucial role when debugging a system. You need clarity on where to log, what to log, and where not to. Now instead of messy logs, I get one clear error log with full context. Debugging feels less like guessing and more like tracing a story. Less logs. Better logs. That’s the real strategy. #BackendDevelopment #Microservices #SystemDesign #Java #SpringBoot #Logging #SoftwareEngineering #CleanCode
To view or add a comment, sign in
-
Spent 25 minutes wondering why my Spring Boot API was returning empty response The controller looked fine @GetMapping("/users") public List<User> getUsers() { return userService.findAll(); } Service was returning data when I debugged But the API response was always empty The problem was the User class had no getters Jackson needs getters to serialize objects to JSON No getters means no fields in the response The fix was adding @Data from Lombok One annotation and everything worked Spring Boot returned the data but Jackson could not read the fields without getters Ever had a bug that made you question everything #Java #SpringBoot #Jackson #Debugging #BackendDevelopment
To view or add a comment, sign in
-
Stop copy-pasting your Spring Security and JWT code from old projects. 🛑 Setting up authentication in a new Spring Boot application is tedious. You need your SecurityConfig, your JwtService, the AuthenticationFilter, the UserDetailsService... it usually takes an hour just to get the boilerplate wired up before you write a single line of actual business logic. I got tired of doing this manually. So, I built a custom "File and Code Template" in IntelliJ IDEA that generates the entire Spring Boot JWT Auth module in exactly 3 seconds. ⏱️ (See the video below 👇) What the template generates instantly: ✅ SecurityConfig (with proper stateless session management) ✅ JwtAuthenticationFilter (extending OncePerRequestFilter) ✅ JwtService (token generation, validation, and extraction) ✅ UserDetailsServiceImpl (database wiring) ✅ AuthController (Signup / Signin endpoints) ✅ DTOs and User Entities Instead of fighting with Spring Security configurations, I can start building features immediately. Automation isn't just about CI/CD pipelines; it's about optimizing your local development workflow to remove friction. If you want the Apache Velocity template code to set this up in your own IDE, drop a "JWT" in the comments and I’ll send you the GitHub Gist! 📩 #SpringBoot #Java #IntelliJ #SoftwareEngineering #DeveloperProductivity #CodingHacks
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