It is sometimes needed to listen to more than one ports with a Spring Boot application. It can be handy, if You need to provide REST API via HTTPS protocol, but you want to provide your diagnostic tool a HTTP port to get application information. You want to hide some of your application's feature behind… Continue reading Define multiple ports for Spring Boot Application
Blog
My favorite Lombok features
I use the Lombok project with a great pleasure. It makes it easier to create a nice code without boilerplate code. My favorite features @Data Maybe the most used annotation. Generates all boilerplate code for a domain object. Getters, setters, equals, hashcode, toString. It is a very good feature to start with. You will never… Continue reading My favorite Lombok features
Batching database operations with Spring and Hibernate
Recently I needed to do some database performance optimization for a Spring Boot application. The application persisted a huge amount of log like data to the Oracle database via Spring JPA. With Hibernate and Spring Data JPA it was not really deficient to write this data, due to the time of single datasource, transaction and… Continue reading Batching database operations with Spring and Hibernate
Restrict number of connected clients for Websocket
Recently I needed to implement a custom check for WebSocket connection of a Spring Boot application. The logic had to check if a configured connection limit has been reached, and reject opening further connections if so. The connections were opened by a mobile application client, and the developer wanted to get the error message in… Continue reading Restrict number of connected clients for Websocket
Setting up MDC context with AOP in Spring Boot application
In order to be able to analyse logs of complex processes for your application, it is useful to use Mapped Diagnostic Context (MDC) and put some process specific information into it. Currently I am implementing a Spring Boot application, with several services, and lots of calls between them. As there is a huge number of… Continue reading Setting up MDC context with AOP in Spring Boot application
Checking parameter of a mocked method call with Mockito
If you are using Mockito, it is sometimes useful to check the parameter state of a method passed to a mocked method call. I use it in the following cases DAO method, like create or update is called in the code. I want to check, if the entity has been set correctly before writing into… Continue reading Checking parameter of a mocked method call with Mockito
Automatic dependency update detection with Gradle
Gradle has the possibility to check if the libraries used by your project has a new version. In order to use the feature, you need to add following elements to your Gradle configuration: buildscript { dependencies { classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0' } } apply plugin: 'com.github.ben-manes.versions' After configuring the project, you can start the following command… Continue reading Automatic dependency update detection with Gradle
Implementing inheritance for JSON objects
Our App developers wanted to send slightly different JSON elements in a single list, in order to make the App side implementation far less complicated. In order to make it possible to, I decided to implement inheritance hierarchy for the JSON input and the related java DTO classes. The other possibility would be to have… Continue reading Implementing inheritance for JSON objects
Tipp and tricks using Spring Data
Spring Data is a very comfortable way of defining DAO objects for your project. It can generate a DAO for your entity class, and provide all basic CRUD functions out of the box. You only need to define an interface, inherited from CrudRepository. For more information of Spring Data basics I recommend reading following resources http://projects.spring.io/spring-data… Continue reading Tipp and tricks using Spring Data
Custom validator for REST parameter in Spring Boot
Using Spring boot applications, it is very easy to let the Spring framework to do the validation of the REST input parameter. You only need to add the corresponding validation annotations to the properties of the parameter class, and mark the parameter with @Valid annotation in the method header. @RequestMapping(value = "/register", method = {… Continue reading Custom validator for REST parameter in Spring Boot