Posts

Showing posts with the label spring-boot

Spring Boot Groovy Console

Image
Observability is a must-have nowadays in modern cloud services. There are multiple levels and options to provide observability into a service. Logging is the basic one but is well used can perform miracles, metrics, dashboards, and alerts and at the top of the chain however, the true nirvana is to have a self-managed / self-healing system and for troubleshooting a query interface. If you let it sink for a moment and think about it you will realize we often had such power in the past with relational databases with a SQL client for instance. However using a Spring Boot stack using polyglot persistence, with JPA, Reactive Programing, Multiple property sources, and Beans it's easy to get into the application and shared libs internals. So what's best? To have access to all properties at runtime and spring beans and be able to execute CODE in a very fluent way. That's where Groovy comes into the play. Inspired by Gabor Bata work , today I will show how we can get that and more w...

Restarting Spring Boot Applications

Image
Spring Boot is the standard framework for developing java services nowadays. It's more than normal to have multiple deploys into productions during the day if you are not trapped by a release calendar or release train which should be a temporary thing and end up being a permanent thing. Ideally, you will have 3 at least 3 instances of your service, one for each availability zone in AWS. In order to introduce changes, DevOps often apply a pattern called Rolled Updates where often you patch one service and restart the application and then you do that one server at a time. In order to do that you server should be able to handle a clean shutdown and manage restarts smoothly which requires some config or code in your service side and also some consideration in sense of release resources, deny connections and prepare the land for a proper restart to happen. You might be in the middle of an important transaction so maybe you want to finish that first. For services is common to use the Sag...

@Value and Spring Properties

Image
@Value annotation allows you to inject either values or results of expression into fields or even methods and constructors. Spring has several mechanisms to deal with configuration and dependency inject. IMHO for Services is more them fine to use all these features, however for libraries we need to be extremely careful and I would say you don't want to use any of these capabilities. We also need to be careful about versioning properties inside jars, especially for libraries. It's very easy to get unpredictable behavior. So great powers require great responsibility and thinking beyond anything I made a video showing some of this feature and also some simple POC - so let's get started!

Spring-Boot Native Image

Image
Spring Boot is the most popular java stack nowadays. New languages like Go and Rust are capable of creating a single binary, self-contained with all deps to run the application. This is great for deployment simplicity but also easier to maintain. As time pass we want to have fast bootup times and do more with less. The native solutions are fast since they are statically compiled for a target platform or OS(in the case of UniKernels). Java was designed to be better as time pass(Runtime) and optimizations kick in. However thats not ideal for Serverless applications. GraalVM changes that since allowing us to compile JVM applications(Java, Scala, Kotlin) to native applications. Today I want to share a simple Video + POC using a new project called Spring Boot Native which allows us to create native images to spring boot apps.  Native images have some challenges like Type Erause for C++ and Reflections in Java. So Let's get started!

FF4J

Image
FFJ4 is a feature flags/toggles solution built in Java with full support and integration with Spring boot. FF4J is rich in features having: Feature Toggles, Role-Based Toggling, Strategy Based Toggling(White/Black Lists, Time Based, Expressions, even has integration with Drools), AOP-Driven Toggling, Features monitoring, Audit Trail, REST API, +20 Databases support, Properties via Spring, Archaius, commons-config or even consul and more.  FF4J has an interesting UI where we can see the toggles and switch them on or off. So today I made a simple video going through the code and also running the UI. So Let's get started!

NetflixOSS Domain Graph Service: GraphQL and Spring Boot

Image
NetflixOSS Released a pretty interesting new solution. A framework for GrpahQL fully integrated with Spring Boot. DGS is super easy to use. You basically have zero effort to use it with Spring boot applications. DSG works with Maven or Gradle, Java, or Kotlin. Some time ago I made some posts about GraphQL and BFF you might want to check it out here and here . You compare with this other approach(also with a video) available here . Without further due, let's get started.  The Video The Code https://github.com/diegopacheco/java-pocs/tree/master/pocs/dsg-fun Cheers, Diego Pacheco

Tests with Spring Boot MockMVC

Image
Spring and Spring Boot provide several ways to test our applications/services. Recently I made a post and video about Testing approaches that might be interesting for you. Previously I also made a post and video about TestRestTemplate  and mocks . For this post, I want to focus a bit on the MockMVC capability. MockMVC has a FakeDispatcher servlet(It will feel pretty real) simulating the MVC stack, however, there are no real network connections being made in practice. So MockMVC provides a lightweight way to test controllers as fast as possible. For this post, we will see a simple POC I wrote with a video going to set up a Spring Boot application and also test some scenarios with the MockMVC feature. So Let's Get Started! 

Spring Boot 2.x TestRestTemplate

Image
Spring has lots of interesting features to make testing easier. There are many ways we can test our application. Often tests are about confidence but not only that tests are also about having a healthy and clean mindset for maintaining systems. For one reason or another there are migrations that need to happen, either for InfoSec remands or Business wants to have a better set of a new feature for user experience or simply the team wants to make the service right and faster. No matter the reason if you have a healthy set of tests your life will be much easier. The building is easier, maintaining system health requires discipline and tests are a  very important part of it. Today I want to show how easy is for us to write proper and yet lightweight integration tests using Spring Boot 2.x and TestRestTemplate. There is a simple application I wrote and also a video which I will cover the code with more depth. So Let's get started.

TLS on Spring Boot 2.4

Image
Security it's super important. Unfortunately, security is often forgotten and the price comes at scale and harassment to your brand and user experience. Spring-Boot is super popular among java solutions in the tech industry at the same time people often run servers without proper TLS configured. There is much mysticism and wrong vision about security. Secure Spring Boot using Tomcat for instance is not hard at all.  Today I want to share a video and code I made showing how we can secure the Spring-Boot 2.x application using Tomcat 9 and doing redirects where users try to reach 8080 port. Customers facing apps should definitely use TLS and HTTPS. However, it's so easy to do for the backend and the overhead is not that bad that we should do it as well. So let's get started. 

Spring Boot 2.x and Mocks

Image
Spring Boot has interesting extensions for mocks using Mockito. Sometimes mocks can be very harried. Unit Tests make sense for services however the cost of mocks sometimes is too high and it could be a very time-consuming and complicated task. Spring-Boot has interesting support together with mockito to make mocks easier and more declarative. Mock is not a free lunch dont get me wrong. However, when you are coding a service Dependency Injection makes sense. Since Dependency Injection makes sense for services why such a thing would not make sense for mocks? Well, it's the same principle. If your implementation relies on dependency injection, your tests should also do the same. I have a bit of different opinion about shared libraries where I dont think they should be coupled with Spring and therefore might not have DI at All. Libraries and Services are completely different animals. Going back to services, today I want to share a video and some sample code I made to show how mocking c...

Hibernate Reactive with Spring Boot 2

Image
Reactive programming is not a new thing. Thanks to reactivex and rx-java it's a reality for almost 10 years. There are other implementations like Project Reactor  and even Vert.x . However, for Databases, we are still not there. Some databases have better support than others like Cassandra and Redis have decent support in drivers but JDBC and JPA are not quite there yet. Hibernate just went reactive. There is a hibernate-reactive project now(still beta 1.0) but looking promising. So today I want to share some simple POC I made to make Hibernate Reactive work with Spring Boot 2.x using webflux: using Netty of course. So I made a video going throught the code and explaining how it works. I personally worked with all sorts of persistence on the last +17 years on technology but not an ORM fan nowadays. However I always appreciate performance and better APIs, so I think this is promising even if is for legacy application modernization.

Spring-Boot-2 with Kotlin

Image
Kotlin  is a Jetbrains language that has lots of inspiration from Scala. Spring-boot-2 is a popular solution for microservices like Quarkus and Micronaut . Today I want to share a simple video I made so you can get started with Maven, Spring-Boot-2, and Kotlin. If you are new to Kotlin I also recommend seeing my previous post about the language. Okay, let's get started. 

Swagger + Spring Boot 2

Image
Swagger is a great API documentation tool. Today I will show how we can generate Swagger Documentation based on a Spring-Boot-2 Application. We will be using SpringFox . Swagger is interesting because you have a very useful contract for services/microservices. It's possible to generate code from that spec and also invoke the services. Spring-Boot is a popular java framework for services/microservices the integration between to solution is more than ideal and SpringFox does that for us effortless. So Let's get started! Video Code https://github.com/diegopacheco/java-pocs/tree/master/pocs/spring-boot-2-swagger-fun Cheers, Diego Pacheco

Spring Boot 2 running with Netty

Image
Spring Boot 2 - It's the default Java way to implement REST endpoints and microservices nowadays. I really miss old days of spring where we used XML and there was no coupling and spring was really lightweight. IMHO Spring is great if you use it under a service, If you use a shared library of the big framework, you can easily get Binary Coupling which will be bad for you in the long run.  Today I want to show how easy is to use Netty. Using netty directly is not that hard and really anyone can use without spring. Netty comes as default dependency if you use webflux instead of the web. So Let's get started. Video Code https://github.com/diegopacheco/java-pocs/tree/master/pocs/spring-boot-2-netty-fun Cheers, Diego Pacheco

Feature Enrichment with Spring Data Redis and Lettuce

Image
Lettuce by far is the best Redis client out there for Java. In the java world, Annotations and Mappings are pretty popular. I build services using these concepts before however they were always under the service boundaries, never as shared libraries in order to avoid coupling. So today I record a video showing how we can use this feature and also extend the functionality to add custom enriched behavior.  We will be using Spring Boot 2, Spring Data Redis, and Lettuce as redis Client. We also will need to have redis running either as standalone / cluster or running on docker. We will create custom annotations in order to describe the behavior we want. I need to say that some people love and other people hate annotations, I have mixed feelings. Often for those that don't like it - check this out . Besides that, let's take a look. So Let's get started.