Micronaut is a new JVM-based framework that is designed for building twelve-factor microservice applications.

The project was initiated by OCI and the team that built the Grails framework, officially announced by Graeme Rocher at Greach Conference 2018, and publicly open-sourced under Apache License 2 on May 23rd, 2018. The first milestone release towards version 1.0.0 was released today, on May 30th, 2018. As the official guide states, “Micronaut is developed by the creators of the Grails framework and takes inspiration from lessons learnt over the years building real-world applications from monoliths to microservices using Spring, Spring Boot and Grails.”

Micronaut’s benefits include a fast startup time and low memory footprint that not only allow the development of serverless applications. …


To activate type checking for all your Groovy classes, you can add the Groovy compilation configuration from this article to your compileGroovy Gradle task. Doing that is equivalent to annotating each class with the @TypeChecked annotation.

apply plugin: 'groovy'compileGroovy.groovyOptions.configurationScript = file('gradle/config/groovyc.groovy')

Add the file Groovy compiler configuration script relative to your :

import groovy.transform.TypeChecked

withConfig(configuration) {
ast(TypeChecked)
}

The configuration references a CompilerConfiguration instance. That’s how you‘ve declared an AST transformation compilation customizer to activate static type checking for all your Groovy files.

When you are using an undeclared variable, the compileGroovy task will throw an error like “[Static type checking] — The variable [naame] is undeclared” now, thus helping you to find typos, unmatched return types, wrong assignments, unavailable variables and methods, you name it. …


The OWASP dependency-check provides monitoring of the libraries you use in your Java project to identify the use of known vulnerable components.

It produces an individual analysis report for the issue of “Using Components with Known Vulnerabilities” which is listed in the OWASP Top Ten 2017.

Gradle plugin

The gradle plugin can create a report of known vulnerable components that are included in the build of your project. You include it in your :

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.owasp:dependency-check-gradle:3.1.2'
}
}

apply plugin: 'org.owasp.dependencycheck'

Afterwards you should integrate the check into your build system by using the…


As of today, Travis CI only supports Java ≤ 9.

But you can download and use another version of the JDK for your Travis CI build. There is a shell-script in the Java Shell Builder project that determines the most recent (early-access) build number (for the JDK version you want), downloads the JDK archive to the user home directory and extracts it there.

I’ve taken some lines from the file from the JUnit 5 project, which is using the mentioned shell-script, to use them in my Java 9/10+ features sample project on GitHub. …


The RemoteWebDriver does not directly implement Selenium’s role interfaces such as WebStorage and LocationContext.

To access that functionality, your driver needs to be augmented with an Augmenter and then cast to the appropriate interface:

WebStorage webStorage = (WebStorage) new Augmenter().augment(driver);LocalStorage localStorage = webStorage.getLocalStorage();SessionStorage sessionStorage = webStorage.getSessionStorage();

I recommend to provide access in a test base class. This is an example I am using for Groovy end-to-end browser tests with Geb:

abstract class EndToEndTest extends GebReportingSpec {  LocalStorage localStorage() {
webStorage().localStorage
}

SessionStorage sessionStorage() {
webStorage().sessionStorage
}

private WebStorage webStorage() {
new Augmenter().augment(driver) as WebStorage
}
}


Spring Boot has default support for Flyway DB, a library for database migrations. Thanks to Spring Boot’s auto-configuration, you just have to provide the dependency to flyway-core and you’re ready to go.

You can use Flyway DB’s afterMigrate callback to prepare the environment with test data. Flyway DB looks after a afterMigrate.sql file in the locations defined by Spring Boot’s spring.flyway.locations setting at startup. The test data is created after all DB migration scripts were executed.

If you want to apply the test data only to a specific environment, you can override the spring.flyway.locations configuration for that stage.

I explain two options for using externalised configuration with Spring Boot that I have experienced in projects in the past, but you have a lot more options. Some of them meet the guidelines of the Twelve-Factor App methodology which requires strict separation of config from code. If the type of config does not vary between deploys it is best done in the code. …


There are several ways to use JUnit 5 with Gradle.

One possibility is to use Gradle ≥ 4.6 which comes with native support for the JUnit platform. Add the following code to your build.gradle to use JUnit 5:

repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.1'
}

test {
useJUnitPlatform()
}

Test logging

java9.collections.MapTest > java9.collections.MapTest$Of.shouldThrowAnExceptionWhenPassedNullValue() PASSEDjava9.collections.MapTest > java9.collections.MapTest$Of.shouldCreateAMapOfTypeImmutableCollections$Map0() PASSED

To get a test logging similar to the above, add the following testLogging to the test closure:

test {
testLogging {
events 'PASSED', 'FAILED', 'SKIPPED'
}
}

There are three additional TestLogEvents: STARTED, STANDARD_OUT and STANDARD_ERROR. To add the Standard-Out and Standard-Error streams, you can also add test.testLogging.showStandardStreams …


The Tagged Image File Format (TIFF or TIF) is a computer file format for storing raster graphics images. If you want to deliver TIFF data with Spring MVC, you basically return the bytes you receive from an input stream to the client.

When the client sends a request with an image/tiff accept header, you send a response back with the content length, the expected content type and the bytes of the TIFF. You can use the following handler method as a reference.

@GetMapping(value="/your-tiff-mapping", headers="accept=image/tiff",
produces="image/tiff")
public ResponseEntity getTiffImage() {
// [...] call some use case and get the output data [...]
return ResponseEntity
.ok()
.contentLength(outputData.getContentLength())
.contentType(MediaType.valueOf("image/tiff"))
.body(outputData.getBytes()); …

In cases where you do not want to handle unique constraint violation errors that are caused by duplicate entries, an UPSERT would be useful to have with PostgreSQL. An UPSERT is similar to an INSERT INTO … IF NOT EXISTS.

In the following example, the users table has a primary key id and a name. By executing the following statement twice …

INSERT INTO users (id, name) VALUES ('fbdf0e604e', 'jonas.havers');

… you will get a unique constraint violation error similar to this:

Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint […]

The PostgresSQL INSERT documentation specifies an ON CONFLICT clause as an alternative to raising a unique constraint or exclusion constraint violation error. …


By default, Spring MVC is tolerant and accepts requests to URL mappings with request URLs both ending with and without a trailing slash if you do not explicitly define one within your mapping.

However, if you want to be more strict about the trailing slashes for certain URLs, i.e. you want some URLs to always end with a trailing slash for SEO reasons but allow access to your application’s internal REST API without the trailing slash as well, you may want to use an OncePerRequestFilter before the requests actually get through to your Spring MVC handler methods.

In this example, all requests to URIs that do not end with a trailing slash are redirected permanently (i.e. with the HTTP status code…

About

Jonas Havers

Remote Freelance Software Engineer. Translates ideas into products with Java, Kotlin, TypeScript and JavaScript. Feedback?@JonasHavers https://jonas-havers.de/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store