In the Spring Cloud family, inter-process communication can be done using RestTemplate or OpenFeign. (Of course there are other ways such as message-driven microservices based on messaging middleware or gRPC-based calls).
RestTemplate can be treated as a common HTTP calling tool, and is particularly convenient for calling RESTful-style interfaces, as opposed to other HTTP clients.
However, more convenient than RestTemplate is OpenFeign, through the interface declaration can achieve remote calls, the specific use of these in the previous article, here will not repeat.
Using native image in spring boot3
Introduction As we introduced in the previous spring boot3 article, one of the important features of spring boot3 is the support for compiling spring boot3 applications into GraalVM Native Images.
Today we use a specific example to show you how to properly compile a spring boot3 application into a native image.
Install GraalVM If you want to compile spring boot3 app as a native application, you need the support of GraalVM.
Java JDK Proxy and CGLib Dynamic Proxy
Introduction The proxy pattern has many application scenarios in Java, and there are static code and dynamic proxies. Static proxies are implemented by weaving in code at writing, compiling or loading time, while dynamic proxies are implemented at runtime. In simple terms, static proxies exist before runtime, while dynamic proxies exist at runtime. And there are two common implementations of dynamic proxies.
JDK Proxy: JDK Proxy comes with the JDK and does not require the introduction of external libraries and is proxied by implementing interfaces.
Uploading folders in Spring Boot applications
Learn how to upload folders in a spring boot application with this article.
HTMLInputElement.webkitdirectory In the browser, we usually select the file to be uploaded by the <input type="file"/> tag. By default, it can only select one file or multiple files, not the whole folder directly.
If the <input/> tag has an attribute called webkitdirectory, the user can select the entire folder and the browser will upload all the files under the folder to the server at once.
New and enhanced features in Spring Framework 6
On November 16, 2022, Juergen Hoeller made the announcement that Spring Framework 6 will be officially released. Spring 6 is a major release, more than four years after the release of Spring 5. Let’s take a quick look at the exciting features in the Spring 6 release in this article.
JDK 17+ and Jakarta EE 9+ baseline Entire framework code base now based on Java 17 source level. Servlet, JPA, etc.
Spring Cache Redis uses SCAN instead of KEYS to match the key to be evicted in bulk
When spring-cache uses redis as the cache implementation, if the cache is deleted in bulk via @CacheEvict(allEntries = true), the KEYS command of redis is used by default to match the keys to be deleted.
Example of using KEYS Define a cache implementation class that removes all eligible caches via the @CacheEvict(allEntries = true) annotation.
1 2 3 4 5 6 7 8 import org.springframework.cache.annotation.CacheEvict; import org.springframework.stereotype.Component; @Component public class FooCache { @CacheEvict(cacheNames = "app::cache", allEntries = true) public void clear () {}; } Run the test method, execute the clear method, and observe the output log.
Spring Boot 3 Upgrade Guide
Spring Boot 3.0 is now available and includes more than 5,700 code commits from 151 developers over 12 months. This is the first major revision of Spring Boot since the release of 2.0 4.5 years ago.
It is also the first Spring Boot GA release to support Spring Framework 6.0 and GraalVM, and the first Java 17-based version of Spring Boot, benchmarked against Jakarta EE 9 and supporting Jakarta EE 10.
Spring Framework 6.0 official GA, the beginning of a new generation of frameworks
Spring Framework 6.0.0 is now available.
This is the start of a new framework generation for 2023 and beyond, embracing current and upcoming innovations in OpenJDK and the Java ecosystem. At the same time, we carefully designed it as a straightforward upgrade from Spring Framework 5.3.x for modern-day runtime environments.
As a major revision to the core framework, Spring Framework 6.0 brings the Java 17+ baseline and migration to Jakarta EE 9+ (in the jakarta namespace) with a focus on the recently released Jakarta EE 10 APIs such as Servlet 6.
Spring Native builds native images without Graal's maven plugin buildtools
Create a Spring Boot project Create a Spring Boot project and add Spring Native dependencies, we are mainly using the AOT functionality provided by Spring Native. As follows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 <dependencies> <dependency> <groupId>org.springframework.experimental</groupId> <artifactId>spring-native</artifactId> <version>${spring-native.version}</version> </dependency> <dependency> <groupId>org.
Spring Boot 3 Observability with Grafana
This article will teach you how to configure observability for your Spring Boot applications. We assume that observability is understood as the interconnection between metrics, logging, and distributed tracing. In the end, it should allow you to monitor the state of your system to detect errors and latency.
There are some significant changes in the approach to observability between Spring Boot 2 and 3. Tracing will no longer be part of Spring Cloud through the Spring Cloud Sleuth project.
Kafka Transactions with Spring Boot
In this article, you will learn how to use Kafka transactions with the Spring Kafka project in your Spring Boot app. In order to run the Kafka cluster we will use Upstash. This article provides a basic introduction to Kafka transactions. If you are looking for more advanced usage and scenarios you may refer to that article, about distributed transactions in microservices. You can also read more about Kafka Streams the Spring Cloud Stream project in this article.
Production Considerations for Spring on Kubernetes
The State of Spring on Kubernetes The 2021 State of Spring report has two main data points:
Spring is the defacto standard for running cloud-native applications in Java. Kubernetes is the defacto standard for running containerized workloads in production. This begs the question - what kind of best practices and considerations should be taken into account when running Spring on Kubernetes?
In this article, I shall highlight some of the learnings and best practices that have formed around running Spring (and more broadly Java) applications on Kubernetes.
Spring Boot 3.0.0 First RC Release
The first RC of Spring Boot 3.0 has been released, along with updates for two branches: 2.7.5 & 2.6.13.
3.0.0-RC1 The release announcement states that this version contains 135 feature enhancements, documentation improvements, dependency upgrades and bugfixes.
Development of Spring Boot 3.0 began with the experimental Spring Native, designed to provide support for GraalVM native images. In this release, developers can now convert Spring Boot applications to native executables using the standard Spring Boot Maven or Gradle plug-ins without any special configuration.
What is aot.factories in Spring 6?
Some of the changes in Spring 6.0, in addition to some of the dependency package adjustments, it seems like not much change. Today I’ll take you deep into the source code to explore the biggest change - the new Graalvm aot support.
1. Spring core Spring framework 6.0 has a major change to Spring core with the addition of the following directories.
GraalVM feature – GraalVM allows clients to intercept native images to generate and run custom code at different stages of initialization.
Fix Undertow outputting warning logs on Spring Boot startup
Using Undertow as a Servlet Container Spring Boot uses Tomcat as the Servlet container by default, but Undertowis gradually gaining more popularity for its excellent performance.
To use Undertow instead of Tomcat in Spring Boot, simply exclude spring-boot-starter-tomcat from the spring-boot-starter-web starter and add the spring-boot-starter-undertow dependency.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.
Embracing Virtual Threads
Project Loom has made it into the JDK through JEP 425. It’s available since Java 19 in September 2022 as a preview feature. Its goal is to dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications.
Where Virtual Threads make sense This makes lightweight Virtual Threads an exciting approach for application developers and the Spring Framework. Past years indicated a trend towards applications that communicate over the network with each other.
How to Deploy Spring Boot Applications to Tomcat Application Server
We sometimes encounter a variety of application servers to deploy in our projects due to the different customers we work with. Although Spring Boot has a built-in Embedded Tomcat server, this is mainly used for development or microservice deployment. If you end up deploying your application to a client’s Tomcat / JBoss EAP / IBM WebSphere environment, you still need to make some adjustments. Today’s article is an in-depth look at the setup process and complete knowledge of deploying to Apache Tomcat®.
Native Support in Spring Boot 3.0.0-M5
The Spring Team has been working on native image support for Spring Applications for quite some time. After 3+ years of incubation in the Spring Native experimental project with Spring Boot 2, native support is moving to General Availability with Spring Framework 6 and Spring Boot 3!
Native images provide almost instant startup time and reduced memory consumption for Java applications. The recent Spring Boot 3.0.0-M5 release marks the first time we’re asking for broader community feedback on our native story.
Spring Profiles in Spring Boot
In any set of development frameworks, multi-environment management is usually one of the important core features, of course, in the Spring framework is no exception, here we call the Spring Profiles. This feature is simple to say, but it is easy to accidentally mess up the implementation, this article I intend to properly sort out some of the concepts to understand, the management up to not mess up.
Create sample applications Quickly building a project using the Spring Boot CLI
PathPattern In Spring MVC
Spring 5 has also been out for a long time, there are some new things we need to explore slowly. Recently, when I was looking at the SpringMVC source code, I saw the following piece of code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 /** * Initialize the path to use for request mapping. * <p>When parsed patterns are {@link #usesPathPatterns() enabled} a parsed * {@code RequestPath} is expected to have been * {@link ServletRequestPathUtils#parseAndCache(HttpServletRequest) parsed} * externally by the {@link org.