Spring Transaction Best Practices

Introduction In this article, I’m going to show you various Spring Transaction Best Practices that can help you achieve the data integrity guarantees required by the underlying business requirements. Data integrity is of paramount importance because, in the absence of proper transaction handling, your application could be vulnerable to race conditions that could have terrible consequences for the underlying business. Emulating the Flexcoin race condition In this article, I explained how Flexcoin went bankrupt because of a race condition that was exploited by some hackers who managed to steal all BTC funds Flexcoin had available.

Tencent officially opens source Spring Cloud Tencent, creating a one-stop microservices solution

Recently, Spring Cloud Tencent was officially open sourced on June 14, as Tencent’s open source one-stop microservice framework, Spring Cloud Tencent implements Spring Cloud standard microservice SPI, developers can quickly develop Spring Cloud microservice architecture applications based on Spring Cloud Tencent. As Tencent’s open source one-stop microservice framework, Spring Cloud Tencent implements the Spring Cloud standard microservice SPI, which allows developers to quickly develop Spring Cloud microservice architecture applications based on Spring Cloud Tencent.

SpringSecurity - Getting information about a logged-in user in a sub-thread

If you want to get the login user information in Spring Security, you can’t get it in a child thread, only in the current thread. One important reason for this is that the SecurityContextHolder stores user information in ThreadLocal by default. However, the SecurityContextHolder actually defines three storage policies. 1 2 3 4 5 6 7 public class SecurityContextHolder { public static final String MODE_THREADLOCAL = "MODE_THREADLOCAL"; public static final String MODE_INHERITABLETHREADLOCAL = "MODE_INHERITABLETHREADLOCAL"; public static final String MODE_GLOBAL = "MODE_GLOBAL"; .

Some Faq about OAuth2

About OAuth2, I believe many beginners have some questions. This article has collected these questions into a QA, which may help OAuth2 learners. FAQ What are the common scenarios for OAuth2? OAuth2 is mainly used for API authorization, which is a solution for authorization between cross API services. It is suitable for single sign-on (SSO), authorization authentication between microservices, API open platform and other scenarios. What is the OAuth2 client?

SpringBoot With Spring Data Jpa

This article teaches you how to quickly integrate and use Spring Data Jpa in your SpringBoot applications. This tutorial uses MYSQL as an example. If you use other databases, e.g. PostgreSQL, then you need to modify the jdbc driver, database, dialect and other related configurations. Practice Required Maven dependencies The required dependencies are as follows. HikariCP mysql-connector-java spring-boot-starter-data-jpa 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 37 <dependency> <groupId>org.

How to get the auto-incremented ID when using JdbcTemplate

This article will teach you how to get auto-incrementing IDs when using JdbcTemplate or NamedParameterJdbcTemplate. Table (MYSQL) Suppose the following data table is available. 1 2 3 4 5 6 7 8 9 10 CREATE TABLE `user` ( `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', `balance` decimal(10,2) DEFAULT NULL, `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `enabled` tinyint unsigned NOT NULL, `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `update_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='user'; As you can see, the id field is an auto-incrementing column.

Spring Announces Spring Security OAuth Reaches End of Life

The Spring Security team has officially announced that Spring Security OAuth has reached the end of its life with the termination of maintenance. The home page of the official website has now been highlighted to alert the complete cessation of maintenance. The old Spring Security OAuth project is terminated to 2.5.2.RELEASE version, and there will be no further iterations of the project, including Bug fixes. We have previously warned that the project will soon be discontinued for maintenance, and those who were paying attention have already migrated.

Spring Cloud Stream RabbitMQ Message Retry

When using Spring Cloud Stream Rabbit, if a consumer throws an exception during consumption. You can re-consume the message in several ways. Option 1 (default) When the consumer side throws an exception while processing a message, then the default will be Retry for 3 times in the current thread. this option is the default and can be modified by modifying the configuration file and specifying the parameters under channel, e.g.

It's time to get ready for Spring Boot 3.0

On February 28, 2018 Spring Boot enters the 2.0 era, more than 4 years ago. in November 2022 Spring Boot 3.0 will be officially released, it will be based on Spring Framework 6.0 and will require Java 17 or higher, and it will be the first Spring for Jakarta EE 9 Boot version for Jakarta EE 9. There are still six months left for developers to transition to Spring Boot

The core knowledge of OIDC certification authorization

OIDC is an authentication layer based on OAuth2, so that the client knows the authorized End User, and provides a user’s authentication information Id Token while the client gets access_token. Widely used in microservices, open platforms, SSO, three-party login authorization and other scenarios. OIDC key terms EU Abbreviation for End User, which refers to an end user. RP Abbreviation for Relying Party, which refers to the trusted client in OAuth2, the consumer of authentication and authorization information.

SpringCloud project transformed into Spring Cloud Kubernetes project

K8S(kubernetes) Kubernetes is an open source for managing containerized applications on multiple hosts in a cloud platform. The goal of Kubernetes is to make deploying containerized applications simple and efficient (powerful), Kubernetes provides a mechanism for application deployment, planning, updating, and maintenance. A core feature of Kubernetes is the ability to autonomously manage containers to ensure that the containers in the cloud platform are running according to the user’s expectations

Voters and voting mechanism for permission management in SpringSecurity

When a user wants to access a protected resource in Spring Security, the user has some roles and the access to the resource requires some roles. The voting machine and voting mechanism are used when comparing the roles the user has with the roles the resource requires. When a user wants to access a resource, the voter votes for or against the resource based on the user’s role, and the voting is based on the results of the voter.

Spring Authorization Server 0.3.0 released, official documentation officially online

Spring Authorization Server 0.3.0 was officially released today, and there are some highlights in this update. Documentation Released The documentation for Spring Authorization Server has been officially released with this update and is now available on the Spring website. Documentation: https://spring.io/projects/spring-authorization-server The document currently contains the following important modules. Project Overview: an introduction and a list of features. Getting Help: Examples, FAQs and issues. Getting Started: System requirements, dependencies, and a guide to developing your first application.

Spring Boot 2.6 + Swagger startup exception: because "this.condition" is null

I tried to upgrade Spring Boot version to 2.6 and got an exception on startup. 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 Caused by: java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null at springfox.documentation.spring.web.WebMvcPatternsRequestConditionWrapper.getPatterns(WebMvcPatternsRequestConditionWrapper.java:56) ~[springfox-spring-webmvc-3.0.0.jar:3.0.0] at springfox.documentation.RequestHandler.sortedPaths(RequestHandler.java:113) ~[springfox-core-3.0.0.jar:3.0.0] at springfox.documentation.spi.service.contexts.Orderings.lambda$byPatternsCondition$3(Orderings.java:89) ~[springfox-spi-3.0.0.jar:3.0.0] at java.base/java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:473) ~[na:na] at java.

Preparing for Spring Boot 3.0

Spring Boot 2.0 was the first release in the 2.x line and was published on Feburary 28th 2018. We’ve just released Spring Boot 2.7 which means that, so far, we’ve been maintaining the 2.x line for just over 4 years. In total we’ve published 95 distinct releases over that timeframe! The entire Spring team, and many in our community of contributors, are nosw preparing for the next generation of Spring. We are planning to release Spring Boot 3.

Several ways to execute code after SpringBoot starts

We often need to do some hook actions when the container starts, such as registering message consumers, listening to configurations, etc. Today we will summarize the 7 startup extensions that SpringBoot leaves to developers. Container refresh completion extension point 1.ApplicationListener<ContextRefreshedEvent> Anyone familiar with Spring must know that a successful container refresh means that all Bean initialization has been completed, and when the container is refreshed Spring will call the onApplicationEvent

Spring Boot 2.7.0 released, 2.5 no longer maintained

These days are “Spring Release Days”, with many Spring artifacts releasing new versions, Spring Framework 6.0.0 released its 4th milestone release, which includes all fixes for 5.3.20, as well as 39 fixes and improvements specific to the 6.0 branch. And yesterday Spring Boot 2.7.0 and several branches of Spring Security were released, especially Spring Boot 2.7.0 which is a very important release. Spring Boot 2.7.0 The most important thing yesterday was the release of Spring Boot 2.

Spring Boot With Spring Hateoas

HATEOAS is a principle to achieve the REST specification, by following the HATEOAS specification, we can solve the actual code to achieve a variety of individual problems. As the most popular framework for java Spring will of course not be absent from the integration of HATEOAS. This article will explain how to use HATEOAS in SpringBoot through a specific example. Our goal The HATEOAS rule returns data with links. Let’s take the familiar Book example to demonstrate this HATEOAS by first creating a Book entity.

Spring Security - Distinguishing login failure exceptions

When we fail to log in, we may write the wrong username or the wrong password, but for security reasons, the server usually does not explicitly indicate whether the username or the password is wrong, but only gives a vague username or password error. However, for many programmers, they may not be aware of the “unspoken rules” that may give the user a clear indication of whether the user name is wrong or the password is wrong.

SpringBoot With Gson

Spring Boot uses Jackson by default as the serialization/deserialization framework for Json. But for me, I prefer Google’s Gson, which is much more concise. This article will teach you how to use Gson instead of Jackson in your Spring Boot application. maven Spring Boot itself provides support for Gson, so you can import the Gson module directly without declaring a version number. If you are not using Jackson elsewhere, then you can exclude it from your project.