Mastodon
All posts tagged

Java

Using Meta-Annotations in Spring MVC Controllers

Using Meta-Annotations in Spring MVC Controllers

I saw a nice best practice recently that I want to share. It’s about how to handle @PreAuthorize annotations in Spring controllers. An architect proposed to ...

Testing Java HTTP Clients with MockWebServer

Testing Java HTTP Clients with MockWebServer

This article briefly introduces the MockWebServer, a nice way to test HTTP calls from a Java application. While reviewing code in one of my major projects, ...

Style Guidelines for Local Variable Type Inference in Java

Style Guidelines for Local Variable Type Inference in Java

A while ago, with Java 10, a new controversial language feature was introduced: var. With var, local variables don’t need the explicit type information on th...

Unit Tests vs Integration Tests

This article will highlight the differences between unit tests and integration tests. It’s widely known that writing tests to increase the quality of softwa...

Moving a Spring-Angular-App from Cloudfoundry to AWS

Recently, I moved the IT Hub from Pivotal Cloudfoundry to Amazon Web Services (AWS). This article highlights some of the decisions and illustrates the result...

How to Start a Spring Boot App with spring-cloud-starter-aws-jdbc dependency locally

To access a database on AWS, the following dependency is needed: implementation('org.springframework.cloud:spring-cloud-starter-aws-jdbc:2.2.4.RELEASE') As...

Returning an empty Responseentity in Spring MVC

Spring MVC is a great way of creating REST interfaces. Many convenience classes and methods are provided, such as the Response Entity object for returning da...

Formatting Currency in Java with string.format

There are common tasks in programming I never performed in a production project. Formatting currency is one of them. I only noticed that when I searched a li...

Java 14 Records

This is just a small code snippet demonstrating the preview of the new Records in Java 14. public record Person( String name, Integer age ) ...

Refactoring your Classes in Axon? Well ...

One of the projects I work in has an uncommon tech stack, at least it differs from the standard CRUD-application-tendency many company-apps are built in. The...

Creating Tables for Hibernate Envers with Liquibase

Recently, I wanted to keep the change history of entities saved via Hibernate and also have a versioned database. Hence, I used Hibernate Envers and Liquibas...

Mockito Verifying Method Arguments with Inorder

Yesterday, I learned how to verify the method parameter for multiple method calls in Mockito. My pair-programmer and I wrote code that send multiple messages...

Spring HATEOAS "links" vs "_links" and JSON Formats

Recently, I added Spring HATEOAS to the IT Hub. Refactoring the controller to return RepresentationModel and CollectionModel, I noticed something odd. When r...

Exposing additional Headers in Requests to Spring MVC so that they can be used in Angular

Working on new features for IT Hub Brunswick, I encountered a curious problem. Sending a POST request from the Angular 8 frontend to the Spring MVC backend r...

Multiple "waiting for Changelog Lock" = Liquibase locked your Database

Some time ago, an application of mine that is deployed in the Pivotal Cloudfoundry began throwing errors and crashed: 2019-09-29T06:42:54.76+0200 [APP/PROC/...

Spring Test Slices

In this article, I want to share what I learned about testing a Spring application without loading it completely. This can be done by using @DataJpaTest, @We...

Cloudfoundry with OpenJDK 11 - Add JBP_CONFIG_OPEN_JDK_JRE

I just upgraded a Java project from Java 8 to OpenJDK 11. The project is running on a Cloudfoundry, using the Java buildpack. After successful deployment wit...

Cloudfoundry not recognizing your App as Spring Boot? Use empty Context Path!

I spend the bigger part of yesterday figuring out why my Spring Boot app was not recognized as such in Pivotal Cloudfoundry app manager. The Spring Boot logo...

LDAP with Spring Security

I spend quite some time implementing a login using Active Directory via LDAP for our Spring Boot 2 application, using Spring Security. This article outlines ...

Using Spring's @value with Defaults

Some values of an application have to be provided from “the outside” of the application, for example the secret of a JSON Web Token (JWT). This secret must r...

Book Review

Book Review "Java by Comparison"

Recently, I finished reading “Java by Comparison – Become a Java Craftsman in 70 Examples” by Simon Harrer, Jörg Lenhard and Linus Dietz. This article is a b...

Spring + Angular + JWT

Learning how an Angular app can be secured with JWT, I found two wonderful blog posts that showed how to implement a basic setup. If forked both of the corre...

Running Test Coverage of Multiple Modules in IntelliJ IDEA

I keep forgetting how to get the overall test coverage of multiple modules in IntelliJ IDEA. There are several ways, here’s my favorite: You can test this...

Stage Switch with Spring

Like other applications, my main project runs through several quality gates before being deployed on the production stage. For example, there is a developer ...

Use Dependency Injection via Constructor

Yesterday, I changed all of our field-injected Spring-dependencies to constructor-injected. This @Autowired private MyOtherService myOtherService; became t...

Folder.listfiles() may produce nullpointerexception

Yesterday, I noticed a strange warning during a code review. IntelliJ IDEA warned me about this code: File folder = new File("path"); if(folder.listFiles() ...

No Database Tables Visible in IntelliJ IDEA

Yesterday, I finally found a solution of one of the most unnerving problems with IntelliJ IDEA. When connecting to my HSQLDB, I couldn’t see any tables. They...

Writing Awesome Java Code Workshop

A couple of weeks ago, I gave another workshop for my colleagues in Braunschweig, Germany. The first thoughts for this workshop came to me months ago. I noti...

How to Solve org.hsqldb.hsqlexception - Statement is closed

A while ago, we fixed a really annoying defect in our code. Because we debugged for days without finding the reason for the defect, I want to share how we ap...

How I use DTOs

How I use DTOs

Because I recently read about this pattern, here are some words about how I use DTOs, Data Transition Objects. DTOs are used to transport data, for example f...

How to Solve incompatibleclasschangeerror

Today I wanted to introduce Degraph in my project to track cyclic dependencies. This got me a java.lang.IncompatibleClassChangeError which I had never seen b...

How I handle equals() and hashcode() in my Project

How I handle equals() and hashcode() in my Project

Some of the problems in everyday software development are luxury problems. Like when you work in a greenfield project and are able to choose how you implemen...

Java Forum Nord 2015 - Functional Programming in Java 8 by Nicole Rauch

Java Forum Nord 2015 - Functional Programming in Java 8 by Nicole Rauch

This article is part of a series about Java Forum Nord 2015, a conference that took place in Hannover, Germany. Links to articles about other talks I visit...

InvalidClassException - Could It Be Your Server?

Yesterday I got a strange exception: 2015-09-29 12:38:07,299 ERROR MyProjectExceptionHandler - Exception: java.lang.RuntimeException: java.io.InvalidClassEx...

Free JavaFX Course Material

Free JavaFX Course Material

Last friday, I gave a JavaFX course for some colleagues. As I did with the Java 8 course, I open-sourced all explanations, examples and code samples. They a...

How to use JDK 1.8u45 in travis or "cannot find symbol" while building Java 1.8u45

While building one of my repositories with Shippable, I got the following error: [ERROR] COMPILATION ERROR : [INFO] ---------------------------------------...

Could not open PerfMemory - Local Java applications cannot be monitored

Today I encountered a strange error opening both Java Mission Control and VisualVM: “Could not open PerfMemory” and “Local Java applications cannot be monit...

Free Java 8 Course Material

Free Java 8 Course Material

Last week, I gave a Java 8 course for some colleagues. All the explanations, examples and code samples of that course are available at Github. Feel free to ...

Removing HTML from Strings with Jsoup

This is an article about a new tool in our project: the library jsoup. I want to describe the problem jsoup solves for us and the arguments why jsoup is th...

JUnit tests with Ant and Hudson

One of my more persistent current problems is the setup of JUnit tests in our Hudson 3.1.1. After days of try and error, I still couldn’t manage to make it w...

Updating an OSGI Based Software System from Java 6 to Java 7

Updating an OSGI Based Software System from Java 6 to Java 7

In this article, I want to describe how we managed to switch from Java 6 to Java 7 and get rid of some issues we found along the way. We use Eclipse 4.2.2 an...

How to Detect Circular Dependencies with Degraph

How to Detect Circular Dependencies with Degraph

Recently, a good friend of mine blogged about Degraph. Degraph is a tool to visualize dependencies between packages. Not only are these dependencies shown i...

Lessons Learned Apache POI

In one of my recent articles, I wrote about my experiences in generating an Excel report with Apache POI. I want to complete my thoughts by summarizing my ...

Prohibit the Use of Methods from Superclasses

A couple of days ago, I saw an interesting way to prohibit the use of a method from a superclass. A coworker of mine wrote a subclass of a JTextField that sh...

Test-Driven Refactoring

Recently, I stumbled over the following code: public boolean someMethod() { List<String> list = getSomethingFromDatabase(); // something is d...

Global Setup Strategy

Recently, I began reading Clean Code by Uncle Bob (again). In chapter 11 (“Systems”), he writes about a “Global Setup Strategy” of an application. As I under...

Hibernate Missing Column ID

This article covers a problem I encountered using Hibernate 3.0 and Spring 2.5.6. Yesterday, I spend one hour to debug the following error from the Hibernat...

Extending Java Enums

I often stumble over ideas that are cool in some way and that I would never have thought about it. One of those ideas is extending Java Enums. Often framewor...