Skip to content

Instantly share code, notes, and snippets.

View msievers's full-sized avatar

Michael Sievers msievers

View GitHub Profile
@msievers
msievers / [jooq] Run jooq codegen without a database.md
Last active October 25, 2018 06:19
Run jooq codegen without a database

Motivation

In order to run jooqs codegen, it needs an appropriate database (with the correct schema) to be running. This often leads to checking in jooq generated code into your applications repository to ease the build process.

Idea

jooq provides an option to run the code generator based on flyway migrations without the need for a specific database to be running. The feature is described here as codegen from DDL.

How it works

@msievers
msievers / [Spring] Make @Async annotated methods run synchronously within (integration) tests.md
Last active October 25, 2018 07:48
[Spring] Make Async annotated methods run synchronously within (integration) tests

Motivation

If you are writing (integration) tests and you want to debug code within the scope of a method annotated with @Async (e.g. an event handler) your IDE might skip over breakpoints within the async code because it might be executed on a different/new thread.

Idea

Replace the default TaskExecutor with an instance of SyncTaskExecutor to ensure, that everything runs on the same thread.

@msievers
msievers / [Spring Cloud, Zookeeper, Configuration] Setup Zookeeper configuration with Spring Boot and Spring Cloud.md
Created April 30, 2021 04:26
[Spring Cloud, Zookeeper, Configuration] Setup Zookeeper configuration with Spring Boot and Spring Cloud

Motivation

With latest release of Spring Cloud 2020.0 (aka Ilford) it's now easier than ever to setup Zookeeper configuration support, but the official documentation currnently lacks some straight-forward example.

Solution

Add the spring-cloud-dependencies bom to the dependencyManagement section of you pom.xml

<dependencyManagement>
@msievers
msievers / [Spring Boot] Disable components for SpringBootTest tests by replacing them with mocks.md
Created February 15, 2019 09:01
[Spring Boot, Spock] Disable components for SpringBootTest tests by replacing them with mocks

Motivation

Annotating a test with @SpringBootTest will usally lead to initializing a Spring context with all components found by Springs component scan mechanism (usally all components of your app). Sometimes, you want some components to be excluded from component scan within your tests, for example

  • startup event listeners
  • setup code which configures external systems/apis/clients etc.
  • ...
@msievers
msievers / ungroup_grouped_objects_in_fabricjs.js
Last active October 14, 2022 12:46
Ungroup programatically grouped objects in fabric.js (simply past this code into the "execute" tab of fabricjs kitchensink demo)
// clear canvas
canvas.clear();
// add red rectangl
canvas.add(new fabric.Rect({
width: 50, height: 50, left: 50, top: 50, fill: 'rgb(255,0,0)'
}));
canvas.add(new fabric.Rect({
width: 50, height: 50, left: 110, top: 50, fill: 'rgb(255,0,0)'
@msievers
msievers / [jooq] Add generic support for Postgres json(b) columns using jacksons JsonNode.md
Last active May 31, 2023 01:36
[jooq] Add generic support for Postgres json(b) columns using Jackson JsonNode

Motivation

jooq does not support Postgres nativ json(b) datatypes out of the box. It would be nice have jooq recognize json columns and provide them in a generic way within generated records.

Idea

The official jooq documentation provides an example for creating a custom data type binding for Postgres json columns using GSON. Based on this, it is possible to tweak the implemenation to

@msievers
msievers / [Spring Boot, Kubernetes] Make a Spring Boot app expose apis on different ports utilizing HandlerInterceptor.md
Created February 15, 2019 10:03
[Spring Boot, Kubernetes] Make a Spring Boot app expose apis on different ports utilizing HandlerInterceptor

Motivation

Assume you have a Spring Boot application which exposes multiple apis, for example one for dogs and one for cats. Let's further assume that the api base paths look something like this

  • /api/cats/v1/
  • /api/dogs/v1/

Especially within kubernetes, it would be slick to be able to expose these apis using dedicated services. Let's recap a simple kubernetes service definition.

@msievers
msievers / [Spring, JMH] Howto integrate JMH benchmarks with Spring.md
Last active March 23, 2024 21:12
[Spring, JMH] Howto integrate JMH benchmarks with Spring

Motivation

Integrate JMH (Java Microbenchmarking Harness) with Spring (Boot) and make developing and running benchmarks as easy and convinent as writing tests.

Idea

Wrap the necessary JMH boilerplate code within JUnit to benefit from all the existing test infrastructure Spring (Boot) provides. It should be as easy and convinent to write benchmarks as it is to write tests.

TL;DR;