Posts

Showing posts with the label Java

Spring: How to deal with circular dependencies

Image
  🔄 Solving Circular Dependencies in Spring Boot: A Complete Guide When your Spring services get tangled up and can't start - here's how to fix it! 🤔 What is a Circular Dependency? A circular dependency happens when two or more Spring beans depend on each other, creating a loop. Spring can't figure out which bean to create first, so your application fails to start. Think of it like this: Service A needs Service B, but Service B also needs Service A - it's like two people waiting for each other to go first through a door! 🚪 💥 How Does It Happen? (Real Example) Let's say you're building an e-commerce app: @Service public class OrderService { @Autowired private PaymentService paymentService; public void createOrder(Order order) { // Process order paymentService.processPayment(order.getPaymentInfo()); } } @Service public class PaymentService { @Autowired private OrderService orderService; // ...

Run AI models in your local machine

Image
Can I run some lightweight AI models on my local machine. How can you do it? Ollama comes to your rescue. Navigate to https://ollama.com/ Download based on your OS and install it. Nothing fancy. Once you've installed it, you can use your terminal to verify the installation. Run: ollama -v Now we are all set to run an AI model on your local machine. Choose any AI model from the list below based on your preference: https://ollama.com/search Consider the size of the AI model because getting a large one might slow down your PC drastically. Let's choose Gemma3, for example: https://ollama.com/library/gemma3 I chose a very basic one with the smallest size: https://ollama.com/library/gemma3:1b So now, to run the Gemma3 AI model in Ollama: Run: ollama run gemma3:1b in your terminal. It's downloading... 💪 once it is downloaded it will start the AI model,  Ask something and see how it replies. That's it for today.. Let's see how we can use Spring AI in the n...

Apache Kafka - The basics

Image
 What is Kafka? Event and Message streaming platform Yes, It is open-source and freely available. There are some commercial availabilities also.  Producers( AKA publishers) push messages/events to Kafka Consumers( AKA subscribers) listen & receive messages/events Publisher ?? Subscriber ??  Don't worry. Let's take a look at it before digging deep. 😊 Publisher Subscriber Pattern. Consider below case. A sender sends message to the receiver.  Sender needs to know the receiver address ( means receiver address should configure in Sender side) Both parties should agreed upon common protocol/format for data sending and receiving.  Now see this case,  Now 3 receiver addresses should configure in sender side.  And if you need to add a new one, then sender side also has a change to be done.  Imagine multiple sender sending multiple receivers ,  Yes. the configuration is a mess now. It is not easy to add a new receiver because there can be many sen...