Depending on your needs using polymorphism might benefit different aspects of the project. For example, having a limited class hierarchy might make your code cleaner and more expressive in contrast to a single class having nullable fields or a type label. And it only seems natural to use it with document-oriented databases like MongoDB. But if you want to have a document with polymorphic fields using MongoDB and Spring Data you might face an exception similar to this: MappingInstantiationException: Failed to instantiate ...FieldType using constructor NO_CONSTRUCTOR with arguments
. Let’s see why this happens and how to fix that issue properly.
spring framework
If you’re using Liquibase for database versioning with Kubernetes to deploy your app, you might have faced an issue when a migration gets stuck because Liquibase can’t acquire lock. It might look somewhat like this:
liquibase.exception.LockException: Could not acquire change log lock. Currently locked by LockOwner ...
at liquibase.lockservice.StandardLockService.waitForLock(StandardLockService.java:236)
at liquibase.Liquibase.update(Liquibase.java:184)
at liquibase.Liquibase.update(Liquibase.java:179)
Code language: Properties (properties)
Continue reading Recently I’ve spent a lot of time making my team’s Grafana dashboards great again. It was all nice & fun adding domain-specific metrics to the dashboard until I realized that I can’t find any values for Spring Boot system metrics like CPU usage or memory usage. What happened to them? Who stole my system metrics?! Let’s find out.
Continue readingI believe that the decorator pattern is one of the most powerful design patterns out there. It is the rule “composition > inheritance” at it’s best: it makes your classes easily testable, it allows to decompose huge classes into smaller ones, and it makes your code reusable and modular. In fact, Spring Framework relies heavily on this pattern. Unfortunately, I think that Spring doesn’t provide a really convenient way to configure decorators with it. This is the second part of how to customize dependency injection in Spring, and today we’re going to see how to make Spring’s DI respect decorators.
Continue readingI work with Spring Framework a lot. I can’t even remember a single project I had at work where I didn’t use it. There is one part of Spring that I use especially often – it’s DI (Dependency Injection). And as often as I use it, I face a situation where it turns out to be not smart enough for me. This article is a result of me trying to customize dependency injection in Spring to make it smarter as well as trying to get a deeper understanding of how does it work. I hope you’ll find it useful as well!
Continue reading