Sometimes, no matter how many features you try to apply, it seems impossible to get Spring Data JPA to apply every thing you’d like to a query before it is sent to the EntityManager .
With 3.0.0-SNAPSHOT (and targeted for the next milestone release train of Spring Data), you now have the ability to get your hands on the query, right before it’s sent to the EntityManager and “rewrite” it. That is, you can make any alterations at the last moment.
Spring application with Gzip compression
Gzip is a compression encoding format. The server often compresses the response body by this encoding and then responds to the client, thus reducing the data size, increasing the transmission speed and saving bandwidth. The client then decompresses it by Gzip to get the original data. It consumes extra CPU resources because of the compression computation required.
Http Header & Encoding There are many other ways to encode similar to Gzip.
Sorting rules for Spring Security filters
How is the order of filters in HttpSecurity maintained? I think many developers are interested in this issue. In this article, I will discuss this issue with you. HttpSecurity contains a member variable FilterOrderRegistration, this class is a built-in filter registry. As for the role of these filters, not the focus of this article, interested to see the FilterOrderRegistration source code. Built-in filter order The FilterOrderRegistration maintains a variable filterToOrder
Mapstruct's new Spring plugin
Mapstruct it can replace BeanUtil to perform conversions between DTO, VO, PO. It uses the annotation processor mechanism of Java compilation period, to put it bluntly, it is a code generator, instead of you manually type conversion during the take value assignment operation. 1 2 3 4 5 @Mapper(componentModel = "spring") public interface AreaMapping { List<AreaInfoListVO> toVos(List<Area> areas); } In just a few lines, a collection of PO is transformed
spring cloud supports heterogeneous language microservices via sidecar
1. Background spring cloud is the de facto standard for microservices in the java application world, it provides very rich and complete microservice components and is very easy to integrate with java applications. However, as many features of spring cloud are integrated into applications through java jar packages in the form of SDK calls (e.g. eureka client, spring cloud config client, etc.), applications developed in other languages (e.g. go, python,
What are microservices?
Microservice is a software architecture that is gaining more and more attention.
But what does it really mean? What kind of architecture can be called microservices?
There are many articles on the Internet, but they are too complicated for beginners to understand. In my opinion, the concept is actually very simple and can be understood in layman’s terms.
1. Monolithic Software To understand microservices, you first need to understand the evolution of software architecture.
How to set SameSite property for Cookie in SpringBoot application?
Starting with Chrome 51, a new SameSite attribute has been added to the browser cookie to prevent CSRF attacks and user tracking.
1. What is a CSRF attack? Cookies are often used to store a user’s identity information, and a malicious website can manage to forge an HTTP request with the correct cookie, which is a CSRF attack.
For example, a user logs into the bank’s website your-bank.com and a cookie is sent from the bank’s server.
How to send multipart/form-data requests via HttpClient
HttpClient is a new client tool class provided by JDK11 under the java.net.http package. This article will teach you how to send multipart/form-data requests through HttpClient.
multipart/form-data The types in the MIME standard can be divided into two categories: standalone types and Multipart types.
Standalone type is a type that represents only a single file or media, indicating the classification of files for the transferred data. Examples include text, application, audio, image, video, etc.
How to Handle Spring Security Exceptions
1. Overview In this article, we’ll have a look at how to handle Spring Security exceptions produced by our Spring Security Resource Server . To do so, we’ll also use a practical example where all the necessary configurations will be explained. First of all, let’s make a short introduction to Spring Security.
2. Spring Security Spring Security is a library that’s part of the Spring project. It tries to group all the functionalities of user access control on Spring projects .
Defending against XSS attacks with Jsoup
XSS An XSS attack is usually a clever way of injecting malicious command code into a web page by exploiting a vulnerability left in the web page’s development, causing the user to load and execute a malicious web program created by the attacker. These malicious web programs are usually JavaScript, but can actually include Java, VBScript, ActiveX, Flash, or even plain HTML, and when the attack is successful, the attacker may gain access to a variety of things including, but not limited to, higher privileges (such as performing certain actions), private web content, sessions, and cookies.
Spring for GraphQL 1.0 RC1 Released
On behalf of everyone involved, I’m pleased to announce the availability of the first and final release candidate of Spring for GraphQL 1.0. We’re finally going to release a 1.0 version on May 17, the reference version for Spring Boot 2.7.0. We’ve shipped a few noteworthy changes and one important new feature in this release.
Note: The Spring for GraphqL Boot starter is up-to-date with the changes discussed in this post and Spring Boot 2.
CORS detailed explanation and how to configure in spring application
CORS explained in detail CORS is a W3C standard, the full name is Cross-origin resource sharing.
It allows the browser to cross-origin server, issued XMLHttpRequest/fetch request, thus overcoming the AJAX can only be used in the same source of the limitations.
1. Introduction CORS requires both browser and server support. Currently, all browsers support this feature, and Internet Explorer cannot be lower than IE10.
The entire CORS communication process is done automatically by the browser, without user involvement.
Spring Security annotated access rights control combing
Spring Security provides annotation-based access control. turns on method annotation access control Spring Security turns off method annotations by default, to turn it on just add the @EnableGlobalMethodSecurity annotation. 1 2 3 4 5 6 7 8 9 10 /** * 开启方法安全注解 * * @author felord.cn */ @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true) public class MethodSecurityConfig { } @EnableGlobalMethodSecurity provides
Spring Cloud - Disable Discovery Clients with Profiles
1. Overview In this tutorial, we’ll look at how to disable Spring Cloud’s Discovery Clients using profiles. This can be useful in situations where we want to enable/disable service discovery without making any changes to the code.
2. Set up Eureka Server and Eureka Client Let’s start by creating a Eureka Server and a Discovery Client.
First, we can set up our Eureka Server using Section 2 of the Spring Cloud Netflix Eureka tutorial.
Spring Framework Data Binding Rules Vulnerability (CVE-2022-22968)
Overview While investigating the Spring Framework RCE vulnerability CVE-2022-22965 and the suggested workaround, we realized that the disallowedFields configuration setting on WebDataBinder is not intuitive and is not clearly documented. We have fixed that but also decided to be on the safe side and announce a follow-up CVE, in order to ensure application developers are alerted and have a chance to review their configuration.
CVE-2022-22968: Spring Framework Data Binding Rules Vulnerability We have released Spring Framework 5.
Ideas for integrating OAuth2 with Spring Cloud Gateway
Microservices to do user authentication and authorization has always been a difficult point, with the OAuth2.0 password mode was invalidated, it is even more difficult.This article will share some ideas.
Two ways of thinking There are usually two ways of thinking about authentication and authorization for microservices.
All authentication authorization is handled by an independent user authentication authorization server, which is only responsible for issuing Token, and then the gateway is only responsible for forwarding requests to each microservice module, and each module of the microservice performs the verification process of Token by itself.
BootstrapMode for JPA Repositories
1. Introduction In this brief tutorial, we’ll focus on the different types of BootstrapMode for JPA repositories that Spring provides for altering the orchestration of their instantiation.
At startup, Spring Data scans for repositories and registers their bean definitions as singleton-scoped beans. During their initialization, repositories obtain an EntityManager immediately. Specifically, they get the JPA metamodel and validate declared queries.
JPA is bootstrapped synchronously by default. Consequently, the instantiation of repositories is blocked until the bootstrap process completes .
Build a Spring Boot REST API with Full-Text Search using Hibernate Search
Search is one of the pillars of the web, and full-text search is one of the mandatory features that every website needs. But implementing such a feature is complex, and lots of skilled engineers have already thought hard about this topic. So let’s not reinvent the wheel, and use the battle-tested Hibernate Search library.
In this blog post, we are going to learn how to build a simple REST API endpoint in Spring boot with full-text search using Hibernate Search.
Build a Spring Boot REST API with Pagination and Sorting
Pagination is an important feature for REST API, and is used for many use cases where we want to fetch only a small part of an entire dataset. It might be for performance reasons, and fetch only the data needed at that time. It can also be used by the frontend to display items using a paginated view type of UI such as infinite scrolling.
Spring Boot provides a pagination feature integrated into the spring data JPA library, making it easy to integrate such a mechanism in our own REST API.
Pagination(with Hateoas), Filtering & Sorting with Spring Boot and JPA
Introduction In this blog post we are going to look at how we can implement pagination with hateoas while supporting filtering and sorting in a spring boot application. We will first start off implementing filtering, and then iteratively page, sorting and finally pagination wtih Hateoas.
Tech Stack Below are the list of languages, frameworks and libraries used in this tutorial
Java 11 Maven h2 in memory database REST apis SpringBoot 2.