<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Spring MVC on Infinite Script</title><link>https://www.infinitescript.com/tags/spring-mvc/</link><description>Recent content in Spring MVC on Infinite Script</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sat, 24 Feb 2018 07:10:14 +0000</lastBuildDate><atom:link href="https://www.infinitescript.com/tags/spring-mvc/index.xml" rel="self" type="application/rss+xml"/><item><title>Getting Started with JUnit 5: Test your Spring MVC Application with it</title><link>https://www.infinitescript.com/2018/02/getting-started-with-junit-5-test-your-spring-mvc-application-with-it/</link><pubDate>Sat, 24 Feb 2018 07:10:14 +0000</pubDate><guid>https://www.infinitescript.com/2018/02/getting-started-with-junit-5-test-your-spring-mvc-application-with-it/</guid><description>&lt;p&gt;In this post, we describe how to use JUnit 5 to test your Spring MVC application with Maven. Before diving into the &lt;code&gt;pom.xml&lt;/code&gt;, it helps to know that JUnit 5 is not a single library but three sub-projects: the &lt;strong&gt;Platform&lt;/strong&gt; (the foundation that discovers and launches tests), &lt;strong&gt;Jupiter&lt;/strong&gt; (the new programming and extension model you actually write tests against), and &lt;strong&gt;Vintage&lt;/strong&gt; (a backward-compatible engine that still runs your old JUnit 3/4 tests). This split is what makes the Maven coordinates below, and the &lt;code&gt;SpringExtension&lt;/code&gt; we plug in later, much less mysterious.&lt;/p&gt;</description></item><item><title>Use Server-Sent Events in Spring MVC</title><link>https://www.infinitescript.com/2015/06/use-server-sent-events-in-spring-mvc/</link><pubDate>Tue, 30 Jun 2015 02:55:32 +0000</pubDate><guid>https://www.infinitescript.com/2015/06/use-server-sent-events-in-spring-mvc/</guid><description>&lt;p&gt;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 &lt;code&gt;SseEmitter&lt;/code&gt; class, and the API has been stable ever since. This post is a practical how-to: we start with a bare &lt;code&gt;SseEmitter&lt;/code&gt;, then build the setup I actually use in production, streaming events from a message queue to the browser.&lt;/p&gt;</description></item><item><title>Use WebSockets with Spring, SockJS and Stomp</title><link>https://www.infinitescript.com/2015/05/use-websockets-with-spring-sockjs-and-stomp/</link><pubDate>Wed, 20 May 2015 14:42:45 +0000</pubDate><guid>https://www.infinitescript.com/2015/05/use-websockets-with-spring-sockjs-and-stomp/</guid><description>&lt;p&gt;This guide walks you through building a &amp;ldquo;hello world&amp;rdquo; 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 &lt;em&gt;subprotocol&lt;/em&gt; that gives the raw bytes some structure. Here we use &lt;a href="https://en.wikipedia.org/wiki/Streaming_Text_Oriented_Messaging_Protocol"&gt;STOMP&lt;/a&gt; messaging with Spring to create an interactive web application.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This post has been &lt;strong&gt;updated for Spring 6/7&lt;/strong&gt;. The WebSocket setup now uses &lt;code&gt;@EnableWebSocketMessageBroker&lt;/code&gt; Java configuration and the modern &lt;code&gt;@stomp/stompjs&lt;/code&gt; client. The original 2015 version targeted Spring 4.1 with XML &lt;code&gt;&amp;lt;websocket:message-broker&amp;gt;&lt;/code&gt; config and the legacy &lt;code&gt;Stomp.over()&lt;/code&gt; API; both are obsolete and have been replaced throughout.&lt;/p&gt;</description></item><item><title>Spring MVC MyBatis Integration Tutorial</title><link>https://www.infinitescript.com/2015/05/spring-mvc-mybatis-integration-tutorial/</link><pubDate>Sun, 03 May 2015 03:20:08 +0000</pubDate><guid>https://www.infinitescript.com/2015/05/spring-mvc-mybatis-integration-tutorial/</guid><description>&lt;p&gt;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.&lt;/p&gt;&#10;&lt;p&gt;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.&lt;/p&gt;</description></item><item><title>Verwandlung Online Judge</title><link>https://www.infinitescript.com/project/verwandlung-online-judge/</link><pubDate>Thu, 30 Apr 2015 18:45:00 +0000</pubDate><guid>https://www.infinitescript.com/project/verwandlung-online-judge/</guid><description>&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;&#10;&lt;p&gt;An &lt;strong&gt;Online Judge (OJ)&lt;/strong&gt; 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.&lt;/p&gt;&#10;&lt;p&gt;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.&lt;/p&gt;</description></item><item><title>Use CDN Service in Spring MVC</title><link>https://www.infinitescript.com/2015/04/use-cdn-service-in-spring-mvc/</link><pubDate>Thu, 02 Apr 2015 15:53:52 +0000</pubDate><guid>https://www.infinitescript.com/2015/04/use-cdn-service-in-spring-mvc/</guid><description>&lt;p&gt;When I deployed &lt;a href="https://www.infinitescript.com/project/testzilla/"&gt;TestZilla&lt;/a&gt; on &lt;a href="https://www.aliyun.com"&gt;Aliyun&lt;/a&gt; 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 &lt;a href="https://stackoverflow.com/questions/28734196/how-to-use-cdn-in-spring-mvc"&gt;asked on Stack Overflow&lt;/a&gt; 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.&lt;/p&gt;</description></item><item><title>Sending Email with Spring MVC Using Template</title><link>https://www.infinitescript.com/2015/01/sending-email-with-spring-mvc/</link><pubDate>Sat, 10 Jan 2015 04:25:34 +0000</pubDate><guid>https://www.infinitescript.com/2015/01/sending-email-with-spring-mvc/</guid><description>&lt;p&gt;This tutorial walks through a small Spring MVC application that sends a templated e-mail, using Thymeleaf to render the message body and Jakarta Mail to deliver it.&lt;/p&gt;&#10;&lt;p&gt;It assumes you are comfortable with Java EE development and with building Spring MVC applications.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This post has been &lt;strong&gt;updated for Spring Framework 7 and Thymeleaf 3.1&lt;/strong&gt;. The original version rendered the message with Apache Velocity, but Spring deprecated its Velocity support in 4.3 and removed it entirely in 5.0; templating is now handled by Thymeleaf, and the mail dependency has moved from &lt;code&gt;javax.mail&lt;/code&gt; to Jakarta Mail (&lt;code&gt;jakarta.mail&lt;/code&gt;).&lt;/p&gt;</description></item><item><title>Spring AOP Example Using Annotation</title><link>https://www.infinitescript.com/2014/10/spring-aop-example-using-annotation/</link><pubDate>Fri, 24 Oct 2014 15:05:50 +0000</pubDate><guid>https://www.infinitescript.com/2014/10/spring-aop-example-using-annotation/</guid><description>&lt;p&gt;Spring Framework is developed on two core concepts – Dependency Injection and Aspect-Oriented Programming (AOP). Today we will look into the core concepts of Aspect-Oriented Programming and how we can implement it using Spring Framework.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This post has been &lt;strong&gt;updated for Spring Framework 7.0&lt;/strong&gt;. The original 2014 version targeted Spring 4.1 with AspectJ 1.8 and the &lt;code&gt;aspectjrt&lt;/code&gt; + &lt;code&gt;aspectjtools&lt;/code&gt; dependencies; it now uses &lt;code&gt;aspectjweaver&lt;/code&gt; 1.9.25 on the current Spring 7.0 GA line. Because Spring 7 builds on Jakarta EE, the servlet types in the examples now come from &lt;code&gt;jakarta.servlet.*&lt;/code&gt; rather than &lt;code&gt;javax.servlet.*&lt;/code&gt;. The AOP concepts and &lt;code&gt;@AspectJ&lt;/code&gt; annotations themselves are unchanged.&lt;/p&gt;</description></item><item><title>Integrate Spring MVC with Log4j</title><link>https://www.infinitescript.com/2014/06/integrate-spring-mvc-with-log4j/</link><pubDate>Tue, 10 Jun 2014 04:46:09 +0000</pubDate><guid>https://www.infinitescript.com/2014/06/integrate-spring-mvc-with-log4j/</guid><description>&lt;p&gt;Integrating Log4j into a Spring MVC application is quite straightforward: include the Log4j library in your project dependencies, then create a &lt;code&gt;log4j.properties&lt;/code&gt; file to define Log4j&amp;rsquo;s appenders and put it on the project classpath. This tutorial walks through that with the Log4j 1.x logging framework.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This post targets &lt;strong&gt;Log4j 1.x&lt;/strong&gt;, which reached end of life in August 2015 and has known vulnerabilities (e.g. CVE-2019-17571, CVE-2021-4104). Treat it as a reference for maintaining legacy projects only. For anything new, prefer &lt;strong&gt;SLF4J + Logback&lt;/strong&gt; (the default in Spring Boot) or &lt;strong&gt;Log4j 2.x&lt;/strong&gt;. Their configuration and API differ entirely from what&amp;rsquo;s shown here, and the official link below now redirects to Log4j 2.&lt;/p&gt;</description></item><item><title>Unit Testing for Spring MVC Controllers</title><link>https://www.infinitescript.com/2014/05/unit-testing-of-spring-mvc-controllers/</link><pubDate>Sat, 17 May 2014 02:09:38 +0000</pubDate><guid>https://www.infinitescript.com/2014/05/unit-testing-of-spring-mvc-controllers/</guid><description>&lt;p&gt;Once the services, DAO, and supporting classes are tested, it&amp;rsquo;s time for the controller. Controllers are often the hardest layer to test, so many developers (based on observation) reach for Selenium or, worse, test by hand. That works, but it makes exercising individual logic branches awkward and slow, and no one wants to wait for a browser to spin up before checking in code. The Spring MVC Test framework solves this by driving full controller logic through fast unit tests, and it has lived in Spring&amp;rsquo;s core ever since Spring 4.&lt;/p&gt;</description></item><item><title>Spring 4 MVC Hello World Tutorial Using Maven</title><link>https://www.infinitescript.com/2014/04/spring-4-mvc-hello-world-tutorial-using-maven/</link><pubDate>Sun, 20 Apr 2014 02:10:48 +0000</pubDate><guid>https://www.infinitescript.com/2014/04/spring-4-mvc-hello-world-tutorial-using-maven/</guid><description>&lt;p&gt;In this tutorial we build the smallest useful Spring MVC application: a controller that reads a request parameter and renders it in a JSP view. It is the classic &amp;ldquo;Hello World&amp;rdquo;, but the wiring it shows (a &lt;code&gt;DispatcherServlet&lt;/code&gt;, a bean configuration, and a view resolver) is the same wiring every larger Spring MVC application is built on.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This tutorial has been &lt;strong&gt;updated for Spring Framework 7&lt;/strong&gt;. It was originally written in 2014 for Spring 4 and the &lt;code&gt;javax.*&lt;/code&gt; servlet API; the configuration below now uses the &lt;code&gt;jakarta.*&lt;/code&gt; namespace, drops the Eclipse-specific setup for a plain Maven command, and runs on Jakarta EE 11 (Tomcat 11+). We keep XML configuration and &lt;code&gt;web.xml&lt;/code&gt; so every piece of the wiring stays visible. The same beans map one-to-one onto a &lt;code&gt;@Configuration&lt;/code&gt; class if you prefer Java config.&lt;/p&gt;</description></item></channel></rss>