You want to initialize a database with different data depending on the data source? Should be straight forward: https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.data-initialization Spring Boot can automatically create the schema (DDL scripts) of your JDBC DataSource or R2DBC ConnectionFactory and initialize it (DML scripts). It loads SQL from the standard root classpath locations: schema.sql and data.sql, respectively. In addition, … Continue reading Initialize a Database Using Hibernate – profile and db based
Category: Spring Boot
Distributed lock on GCP Datastore
So, I needed a distributed lock on the GCP Datastore. In theory, it is all very simple: Get the lockDo what you need to doRelease the lock And, when I started thinking about it, it became clear that I need to have some kind of transaction mechanism in order to obtain the lock. Basically, when … Continue reading Distributed lock on GCP Datastore
Spring Integration Testing – WireMock and MQ
When writing integration tests for parts of the application that talk to other applications, for example calling REST APIs or sending JMS messages, sometimes we just want to test the application and not do end to end test. In this case, we would need to mock these other applications or their behavior. Mocking REST For … Continue reading Spring Integration Testing – WireMock and MQ
Multiple projects inside one IntelliJ instance
When you are working with multiple projects, for example a number of microservices, it becomes problematic to have an IntelliJ instance open for each of those. There is a trick that allows us to have multiple projects open inside one IntelliJ instance (this saves time, space and RAM :)). Basics steps are as follows: Create … Continue reading Multiple projects inside one IntelliJ instance
MapStruct
When working with Spring services and exposing REST API calls, you would usually want to have a set of customized objects exposed to the outside world. These objects, usually called DTOs, can expose some of the domain objects or some projection made out of domain objects (or something else). For mapping between domain data objects … Continue reading MapStruct
SpringBoot, Axon, Multiple Data Sources = ? are you doin’?
Ok, so, after playing with this for few days, I have decided to put this into a form of a post, to serve mostly as a reference for anyone facing the same or similar problem. After all, how do you think I solve my problems? Just like that, I search online for solution, then for … Continue reading SpringBoot, Axon, Multiple Data Sources = ? are you doin’?
Run SpringBoot app inside alpine docker container
# From alpine:latest FROM alpine # Install open JDK 11 RUN apk add openjdk11 # Create temp volume VOLUME /tmp # Add and run your app ADD /spring-boot-web-0.0.1-SNAPSHOT.jar myapp.jar ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/myapp.jar"] Build the image: docker build -t alpine-java-3 . Run the image, map the ports 8080 to host machine: docker run -d … Continue reading Run SpringBoot app inside alpine docker container
Maven/Gradle – exclude tests
Excldue tests in Maven, example: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <excludes> <exclude>com/dimitar/reactive/springreactive/fluxandmono/*.java</exclude> <exclude>com/dimitar/reactive/springreactive/handler/*.java</exclude> <exclude>com/dimitar/reactive/springreactive/controller/*.java</exclude> </excludes> </configuration> </plugin> ... </plugins> </build> Maven documentation. Exclude tests in Gradle, example: test { exclude 'com/dimitar/reactive/springreactive/fluxandmono/**' } Gradle documentation.
Spring external .properties file
Before we proceed, be sure the check out the spring-cloud-config. Depending on your use case, this might be what you want , Spring Cloud Config. Lets say that we have following .properties files in our project: application.propertiesapplication-dev.propertiesapplication-prod.propertiescustom.properties Spring will use these files, if we do not tell it otherwise. We can override the location of … Continue reading Spring external .properties file
Remote debugging Spring Boot App
I have an application running on a remote server and I need to debug it. Don't worry, server is firewall-ed and access is strictly controlled. What we want to achieve is to run the spring boot application in debug mode. We need to tell the VM to run in debug, how we will connect to … Continue reading Remote debugging Spring Boot App