Common Patterns in Distributed Systems

Sample application: Microservices Patterns: Enterprise Integration Patterns: Configuration Management Centralizing configuration and secret values: AWS Secrets Manager AWS Key Management Service Apache ZooKeeper Spring Cloud Config (Spring Cloud Vault, Spring Cloud Zookeeper) etcd – distributed reliable key-value store Service Discovery Client make request to Service Registry or Load Balancer (Router): Apache […]

PostgreSQL quick start

How to install PostgreSQL with brew:

add to startup:


or manually:

with ctl:

check status:



How to setup PostgreSQL

quit psql:

create application user and database

setup password for user:


Initialization List with values in one row in Java

Java 9: List.of(“a”, “b”, “c”); Set.of(“a”, “b”, “c”); Java 8: Stream.of(“a”, “b”, “c”).collect(Collectors.toList()); Stream.of(“a”, “b”, “c”).collect(Collectors.toCollection(ArrayList::new)); Older: Collections.singletonList(); Arrays.asList(); new ArrayList() {{ add(“a”); add(“b”); add(“c”); }};

Mockito, Spy, PowerMock


Mockito Mocks vs. Spies Mock – bare-bones shell instance

Spy – wrap an existing instance

PowerMock final classes without interfaces static methods privates

Test-driven development: JUnit



Expected Exceptions Test

@RunWith BlockJUnit4ClassRunner – default junit runner SpringJUnit4ClassRunner allows you to use dependency injection in test classes or to create transactional test methods. MockitoJUnitRunner for automatic mock initialization. Suite Parameterized Parameters class

JUnit 5 – @ExtendWith

replace with


or your custom rule: […]

Hibernate – OneToOne, OneToMany, ManyToOne, ManyToMany mappings

By specifying the @JoinColumn on both models you don’t have a two way relationship. mappedby One to One

bidirectional One to One is EAGER @MapsId (before jpa2 – @PrimaryKeyJoinColumn)

One To Many, Many To One Unidirectional without @JoinColumn requires additional table for joining


Is it possible to limit the […]

Hibernate – JPA

SessionFactory (jpa: EntityManagerFactory) – thread-safe (and immutable) representation of the mapping of the application domain model to a database Session (jpa: EntityManager) – A single-threaded, short-lived object conceptually modeling a “Unit of Work” StatelessSession – like JDBC Transaction (jpa: EntityTransaction) – A single-threaded, short-lived object used by the application to demarcate individual physical transaction […]

Spring Bean Life Cycle

By implementing InitializingBean and DisposableBean interfaces Providing init-method and destroy-method in xml configuration or @PostConstruct and @PreDestroy annotations for methods

For activating post processor annotation annotations use

or by

used to activate applied annotations in already registered beans in application context (context:component-scan does what context:annotation-config does, but additionally it scan the […]