JSR303 verification usage and how to customize verification annotations

One, JSR303 JSR303 is a standard framework provided by Java for Bean data validity verification. It has been included in JavaEE6.0. JSR303 specifies verification rules by annotating standard annotations such as @NotNull @Max in Bean attributes and passes standard verification. The interface verifies the Bean. 2, JSR303 common annotations Annotation Function @Null The annotated element […]

2023.11.6 Spring uses annotations to store Bean objects

Table of Contents Preliminary work Use class annotations Five categories of annotations @Controller @Service @Repository (warehouse) @Component @Configuration Use method annotations @Bean Rename Bean Additional questions Relationship between class annotations Preliminary work Configure the scan path in the configuration file <?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.springframework.org/schema/beans” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:content=”http://www.springframework.org/schema/context” xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/ context https://www.springframework.org/schema/context/spring-context.xsd”> <!–base-package indicates the […]

03-Implementing AOP based on annotations

Using Spring’s AOP AspectJ is a framework organized by Eclipse that supports AOP. It is a framework independent of the Spring framework. Spring’s implementation of AOP includes several methods The first way (commonly used): AOP implemented by the Spring framework combined with the AspectJ framework based annotation method The second method (commonly used): Spring framework […]

Project practice: add four annotations @Controller and @Service@Repository@Autowire

1.@Controller package com.csdn.mymvc.annotation; import java.lang.annotation.*; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface Controller { } 2.@Service package com.csdn.mymvc.annotation; import java.lang.annotation.*; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface Service { } 3.@Repository package com.csdn.mymvc.annotation; import java.lang.annotation.*; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface Repository { } 4.@Autowire package com.csdn.mymvc.annotation; import java.lang.annotation.*; @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface Autowire { } 1. FruitController package […]

Why you should stop using field annotations in SpringBoot and use constructor injection instead

Stop using field injection in SpringBoot! This article is a translation, and I have added some of my own understanding. Translation source: https://medium.com In the context of Spring Boot dependency injection, there is a debate about best practices for injecting dependencies: field injection, setter injection, and constructor injection. ?In this article, we will focus on […]

Spring’s @FieldDefaults and @Data: Lombok annotations for cleaner code

Introduction As Java developers, we often find ourselves stuck in boilerplate code. Accessor methods, modifier methods, constructors, equals(), hashCode(), and toString() are essential, but take up a lot of space and distract from the core logic of the application. The Spring framework is widely used for building enterprise applications and is a fan of reducing […]

Annotations elegantly implement Redisson distributed locks

1Foreword In daily development, it is inevitable to encounter some concurrency scenarios. In order to ensure the consistency of interface execution, locking is usually used. Because the service is a distributed deployment mode, the local locks Reentrantlock and Synchnorized are put aside first. Redis’s The problem of setnx lock being unable to guarantee atomicity will […]

spring, springMVC, mybatis annotations

SSM annotations 1. Mybatis annotations @Param: used to pass parameters so that they can correspond to field names in SQL @Insert: Implement new addition, instead of @Delete: Implement deletion instead of @Update: Implement updates instead of @Select: implements query instead of @Result: Implement result set encapsulation instead of @Results: Can be used together with @Result […]