Java
Getting Started with JUnit 5: Test your Spring MVC Application with it
In this post, we describe how to use JUnit 5 to test your Spring MVC application with Maven. Before diving into the pom.xml, it helps to know that JUnit 5 is not a single library but three sub-projects: the Platform (the foundation that discovers and launches tests), Jupiter (the new programming and extension model you actually write tests against), and Vintage (a backward-compatible engine that still runs your old JUnit 3/4 tests). This split is what makes the Maven coordinates below, and the SpringExtension we plug in later, much less mysterious.
Single Sign-On with Apereo CAS
This tutorial walks a newcomer through standing up an Apereo CAS server for single sign-on and wiring a Java web application to it as a client. The complete CAS 7.1 server is available as a companion WAR overlay on GitLab. Note: This post has been rewritten for Apereo CAS 7.x. It was originally written for CAS 4.x, which you set up by copying the server source and hand-editing a pile of XML files (deployerConfigContext.xml, ticketGrantingTicketCookieGenerator.xml, …). CAS has changed completely since: the org.jasig.cas packages became org.apereo.cas, and the server is now built as a Spring Boot WAR overlay configured through a single cas.properties file.
Introduction to Java Virtual Machine
Note: This article has been updated for Java 8 and later. The original 2015 version described the Permanent Generation (PermGen), which Java 8 removed and replaced with Metaspace (JEP 122); the garbage-collection section has also been rewritten to cover the modern HotSpot collectors (G1, ZGC, Shenandoah). The behaviors described here are those of HotSpot; other JVM implementations may differ. What is JVM? The Java Virtual Machine is the cornerstone of the Java platform. It is the component responsible for Java’s hardware and operating-system independence, the small size of its compiled code, and its ability to protect users from malicious programs.
Use Server-Sent Events in Spring MVC
Server-Sent Events (SSE) let a server push a continuous stream of updates to the browser over a single long-lived HTTP connection. Spring has supported them since version 4.2 through the SseEmitter class, and the API has been stable ever since. This post is a practical how-to: we start with a bare SseEmitter, then build the setup I actually use in production, streaming events from a message queue to the browser.
Use WebSockets with Spring, SockJS and Stomp
This guide walks you through building a “hello world” application that sends messages back and forth between a browser and the server. WebSocket is a very thin, lightweight layer on top of TCP, which makes it a natural place to run a subprotocol that gives the raw bytes some structure. Here we use STOMP messaging with Spring to create an interactive web application. Note: This post has been updated for Spring 6/7. The WebSocket setup now uses @EnableWebSocketMessageBroker Java configuration and the modern @stomp/stompjs client. The original 2015 version targeted Spring 4.1 with XML <websocket:message-broker> config and the legacy Stomp.over() API; both are obsolete and have been replaced throughout.
Spring MVC MyBatis Integration Tutorial
A while back I built a project on Spring MVC and Hibernate, then wanted to see how MyBatis compares. This article shows how to wire MyBatis into Spring MVC, and how to let Spring manage MyBatis transactions for you. A database transaction is an all-or-nothing unit of work: either every statement in it takes effect, or none of them does. We lean on that property at the very end, where a single bad row makes an entire batch insert roll back.
Verwandlung Online Judge
Stars Live verwandlung.org Introduction An Online Judge (OJ) is a web-based system used in competitive programming. It presents algorithmic problems, accepts code submissions in various languages, automatically compiles and runs the code against hidden test cases, and immediately tells the user whether their solution is correct, all without any human involvement in the grading process. Platforms like LeetCode and Codeforces are well-known examples. Verwandlung Online Judge is a self-hostable, open-source OJ built for running your own contests or practice environment. Its main distinguishing feature at the time of release was cross-platform support: most open-source OJs were Linux-only due to their reliance on Linux-specific sandboxing APIs, whereas Verwandlung runs natively on both Windows and Linux.
Use CDN Service in Spring MVC
When I deployed TestZilla on Aliyun Elastic Compute Service, growing traffic made it worth offloading static files (images, CSS, and JavaScript) to a CDN. At the time there was little guidance on wiring a CDN into Spring MVC, so I asked on Stack Overflow and ended up with the setup below. The idea is simple: keep the CDN host in a single property and inject it wherever your JSP views reference static assets.