🚀 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
Spring Boot Custom Auto-Configuration
More Relevant Posts
-
🚨 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
-
🚀 Mastering Spring Boot – Step by Step (Day 2) Still using "new" in Spring? ❌ 👉 Then you’re missing the core idea of Spring 💡 What is a Spring Bean? A Bean is: 👉 Any object managed by the Spring IoC container Instead of: UserService service = new UserService(); Spring does: ✔ Create objects ✔ Manage lifecycle ✔ Connect components 💡 What is IoC (Inversion of Control)? 👉 You don’t control object creation anymore 👉 Spring does it for you This leads to: ✔ Cleaner code ✔ Loose coupling ✔ Better scalability 💡 Simple way to think: You: "I will create objects" ❌ Spring: "I will handle everything" ✅ 👉 This is the foundation of Spring Next → Dependency Injection (real magic begins) 🔥 #Spring #SpringBoot #Java #Backend #LearningInPublic
To view or add a comment, sign in
-
Last week, I was debugging a strange issue in my Spring Boot application.Everything worked fine locally… but suddenly started breaking in production. After hours of digging, the culprit wasn’t my code. It was a transitive dependency. What is a Transitive Dependency? In a Maven-based Spring Boot project, you add a dependency like this: <dependency> <groupId>org.springframework.boot </groupId> <artifactId>spring-boot-starter-web </artifactId> </dependency> Looks simple, right? But behind the scenes, this pulls in many other dependencies automatically (like Jackson, Tomcat, etc.). These indirect dependencies are called transitive dependencies. The Problem: In my case, two different libraries were pulling different versions of the same dependency. Result? 1. Runtime conflicts 2. Unexpected errors 3. Debugging nightmare How I Fixed It: Step 1: Identify the dependency tree mvn dependency:tree Step 2: Find conflicting versions Step 3: Exclude unwanted dependency <dependency> <artifactId>koi</artifactId> <exclusions> <exclusion> <groupId>congflict</groupId> <artifactId>conflicting.any</groupId> </exclusion> </exclusions> <dependency> Step 4: Add the correct version explicitly Use: 1. mvn dependency:tree 2. mvn dependency:analyze These commands can save hours of debugging. Key Takeaway: Transitive dependencies are powerful…but if ignored, they can silently break your application. Always know what comes along with what you import. #Java #SpringBoot #Maven #BackendDevelopment #Debugging #SoftwareEngine
To view or add a comment, sign in
-
-
Spring Boot Magic #4 ✨ — Starter Dependencies One thing I feel is underrated in Spring Boot… is how powerful starter dependencies actually are. We use them every day, but rarely think about how much work they’re saving us. Just add one dependency… and boom 💥 Everything is auto-configured and ready to use. Some underrated but super useful starters 👇 👉 spring-boot-starter-validation Handle validations with simple annotations like @NotNull, @Email — clean & easy 👉 spring-boot-starter-data-jpa No need to write basic SQL — just interfaces and you’re good to go 👉 spring-boot-starter-security Add authentication & authorization with minimal setup 👉 spring-boot-starter-actuator Production-ready endpoints for health, metrics, monitoring 👉 lombok (not a starter but a lifesaver 😄) Removes boilerplate like getters, setters, constructors We use these almost daily… but don’t always realize how much complexity they hide. Sometimes, the real magic is just one dependency away 🚀 #SpringBoot #Java #BackendDevelopment #CleanCode #DeveloperLife
To view or add a comment, sign in
-
-
🚀 Understanding the #Main_Class in #SpringBoot Today I learned the heart of every Spring Boot application — the Main Class 💻 @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } 💡 What does @SpringBootApplication do? This single annotation combines three powerful annotations 👇 ✔ @Configuration → Marks the class as a source of bean definitions ✔ @EnableAutoConfiguration → Automatically configures Spring Boot based on dependencies ✔ @ComponentScan → Scans and loads components like Controllers, Services, and Repositories ✨ In simple words: This class is the starting point of the application. When we run it, Spring Boot scans the entire project, loads all required configurations, and starts the embedded server automatically 🚀 Understanding this gave me clarity on how Spring Boot boots up the whole application 🔥 #SpringBoot #Java #BackendDevelopment #LearningJourney #10000 Coders #DeveloperLife
To view or add a comment, sign in
-
-
🚨 Spring Boot is NOT Magic — Here’s What Actually Happens Many developers use Spring Boot daily… But can’t explain what happens behind this line: 👉 @SpringBootApplication Let’s break the “magic” 🔥 That single annotation actually does 3 things: ✅ @Configuration → Defines beans ✅ @EnableAutoConfiguration → Auto-configures based on classpath ✅ @ComponentScan → Scans your packages for components 💡 The real power is in Auto-Configuration Spring Boot checks: 👉 What dependencies are present? 👉 What beans are missing? Then it automatically configures things for you. Example: If spring-boot-starter-web is present → ✔ DispatcherServlet is configured ✔ Embedded server (Tomcat) starts ✔ MVC config is applied ⚠️ Where most candidates struggle: They say: ❌ “Spring Boot automatically does everything” But can’t explain: 👉 How beans are created 👉 How conditions work (@Conditional) 👉 How to override default configs 🎯 What strong engineers know: • How AutoConfiguration classes work • How Spring decides which bean to create • How to debug startup issues (logs, conditions report) 🔥 Interview Tip: Next time someone asks “How Spring Boot works?” Don’t say “auto configuration happens” Say: 👉 “Spring Boot uses conditional auto-configuration based on classpath and bean context” #springboot #java #backend #microservices #softwareengineering #interviewprep #techlearning
To view or add a comment, sign in
-
Most people use Spring Boot. But very few understand what actually happens when the application starts While going deeper into it, a few things started making more sense How the application context is created What SpringBootApplication really triggers How the bean lifecycle actually works Why proxies are used for things like Transactional And how self invocation can silently break things It is easy to write Spring code Understanding what happens inside is different Still learning and connecting the dots What part of Spring feels confusing to you #Java #SpringBoot #BackendDevelopment #SoftwareEngineering #JavaDeveloper #SystemDesign #Placements
To view or add a comment, sign in
-
-
🚀 30 Days of Spring Boot – Day 2 Today I explored one of the core foundations of Spring — Beans & Their Management. 🔹 What I learned: ✅ Spring Bean A Bean is a Java object managed by the Spring IoC container. Instead of creating objects using new, Spring handles creation, lifecycle, and dependency injection. ✅ @Bean Annotation Used to manually define a Bean inside a @Configuration class. It gives full control over object creation — especially useful for third-party classes or custom configurations. 💡 Even though we use new inside a @Bean method, it is executed only once by Spring (Singleton scope by default) and reused across the application. ✅ Bean Scope Defines how many instances Spring creates: Singleton → Single shared instance (default) Prototype → New instance every time Request → Per HTTP request Session → Per user session 🔥 Key Takeaway: “Write new once, let Spring manage and reuse the object everywhere.” 📌 Strengthening fundamentals step by step. #SpringBoot #Java #BackendDevelopment #LearningJourney #100DaysOfCode #Microservices
To view or add a comment, sign in
-
⚙️ One Spring Boot Practice That Changed My Code Quality I stopped using field injection. ❌ @Autowired on fields ✅ Constructor Injection Why? ✔ Better testability ✔ Immutable dependencies ✔ Cleaner design Small change… big impact. If you’re still using field injection — try this once. What’s your preferred approach? 🤔 #SpringBoot #Java #BestPractices
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
-
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