🚀 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
Spring Boot Auto-Configuration Simplifies Setup
More Relevant Posts
-
🧠 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
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
-
Most developers return wrong HTTP status codes. Here's the correct way 👇 I see this mistake constantly in code reviews: return ResponseEntity.ok(null); // ❌ Wrong for errors return ResponseEntity.ok("User deleted"); // ❌ Wrong for DELETE The correct way: ✅ 200 OK — GET request success, data returned ✅ 201 CREATED — POST success, resource created ✅ 204 NO CONTENT — DELETE success, nothing to return ✅ 400 BAD REQUEST — Invalid input from client ✅ 401 UNAUTHORIZED — Not logged in ✅ 403 FORBIDDEN — Logged in but no permission ✅ 404 NOT FOUND — Resource doesn't exist ✅ 409 CONFLICT — Duplicate data (email already exists) ✅ 500 INTERNAL SERVER ERROR — Something broke on server Spring Boot example: return ResponseEntity.status(HttpStatus.CREATED).body(savedUser); Correct status codes make your API professional, predictable, and frontend-developer friendly. Save this. Share with your team. Which status code do you see misused most? 👇 #SpringBoot #RestAPI #Java #BackendDevelopment #APIDesign
To view or add a comment, sign in
-
-
🚀 Day 20/100: Spring Boot From Zero to Production Topic: Custom Auto-Configuration We covered Auto-Configuration. We covered disabling it. But does it stop there? Nope. 👀 Spring Boot lets you build your own auto-configuration too. 🔧 But, How It Works? You create a @Configuration class and slap conditionals on it. Spring Boot only loads it if your conditions are met. Two most common ones: @ConditionalOnClass → Load only if a class exists on the classpath @ConditionalOnProperty → Load only if a property is set in application.properties 💡 See the code attached below. ⬇️ No DataSource on classpath? → Skipped entirely db.enabled=false? → Skipped entirely Bean already defined by user? → Your default is skipped ✅ 📌 Don't forget to register it In META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports: -> com.yourpackage.MyDataAutoConfiguration Without this, Spring Boot won't pick it up. Checkout the previous posts on Auto-Config & disabling it to better understand the sequence. See you in the next one! #Java #SpringBoot #SoftwareDevelopment #100DaysOfCode #Backend #AutoConfiguration
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
-
-
As developers, we all say *“async = separate thread”*… but when I went deeper during development, a few real questions hit me 👇 Can I actually **see which thread is running my async task?** Yes — using `Thread.currentThread().getName()` you can log and observe it. But then the bigger question… 👉 **How many threads are actually created?** 👉 Is it always a new thread per task? 👉 Or are threads reused? I came across a post saying **“by default 8 threads are used”** — but is that really true in all cases? From what I understand so far: * It depends on the **thread pool configuration** * Frameworks like Spring Boot often use executors (not raw thread creation) * Threads are usually **reused**, not created every time But I want to hear from real-world experience 👇 💬 How does async actually behave in production systems? 💬 What decides the number of threads? 💬 Any pitfalls you’ve seen while working with async? Let’s learn from each other 🚀
To view or add a comment, sign in
-
🚀 Day 99/100 - Spring Boot - Creating Custom Starters Just to understand... How Spring Boot gives you ready-to-use features with just a dependency? 🤔 it's actually due to"starters"... Let's try to learn how to create your own custom starter❗ ➡️ What is a Custom Starter? 🔹A reusable module that auto-configures beans 🔹Plug-and-play functionality via dependency 🔹Helps standardize setups across projects ➡️ Steps to Create Custom Starter 1️⃣ Create a separate module e.g., my-spring-boot-starter 2️⃣ Add dependency spring-boot-autoconfigure 3️⃣ Register Auto-Configuration For Spring Boot 3: META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports com.example.autoconfig.MyAutoConfiguration ➡️ Example Auto-Configuration (see attached image 👇) ➡️ How to Use It? 🔹Add your custom starter as a dependency in another project 🔹Beans get auto-configured automatically 👉 Key Takeaway Custom starters let you package your own “mini Spring Boot features” and reuse them anywhere... Previous post - Creating And Listening to Custom Events: https://lnkd.in/dw9_evXQ #100Days #SpringBoot #Java #AutoConfiguration #BackendDevelopment #SoftwareEngineering
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
-
Learnt about basic setup of a spring boot project. How we can create a spring boot project, how we can run it, whats each file in the starter project for, whats pom.xml, what are application properties, how to hook up spring boot web starter pack for dependencies using maven central, What a controller is, how can we create a basic controller etc. #BACKEND #JAVA #SPRINGBOOT #SOFTWAREENGINEER
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