Spring Boot 注解大全:全面解析與實戰應用

目錄

一、Spring Boot 啟動與配置相關注解

1.1?@SpringBootApplication

1.2?@EnableAutoConfiguration

1.3?@Configuration

1.4?@ComponentScan

二、依賴注入與組件管理注解

2.1?@Component

2.2?@Service

2.3?@Repository

2.4?@Controller

2.5?@RestController

2.6?@Autowired

2.7?@Qualifier

2.8?@Resource

2.9?@Value

三、Web 開發相關注解

3.1?@RequestMapping

3.2?@GetMapping、@PostMapping、@PutMapping、@DeleteMapping、@PatchMapping

3.3?@PathVariable

3.4?@RequestParam

3.5?@RequestBody

3.6?@RequestHeader

3.7?@CookieValue

3.8?@ModelAttribute

3.9?@SessionAttributes

四、數據訪問與事務管理注解

4.1?@Entity

4.2?@Table

4.3?@Id

4.4?@GeneratedValue

4.5?@Column

4.6?@Repository

4.7?@Transactional

五、AOP 相關注解

5.1?@Aspect

5.2?@Pointcut

5.3?@Before

5.4?@After

5.5?@AfterReturning

5.6?@AfterThrowing

5.7?@Around

六、測試相關注解

6.1?@SpringBootTest

6.2?@MockBean

6.3?@WebMvcTest

6.4?@DataJpaTest

七、其他注解

7.1?@Conditional

7.2?@ConditionalOnClass

7.3?@ConditionalOnMissingBean

7.4?@ConditionalOnProperty

7.5?@Scheduled

7.6?@EnableScheduling

7.7?@EnableAsync

7.8?@Async

7.9?@ConfigurationProperties

7.10?@EnableConfigurationProperties


一、Spring Boot 啟動與配置相關注解

1.1?@SpringBootApplication

這是 Spring Boot 應用中最核心的注解,通常位于主應用類上。它是一個組合注解,實際上包含了?@Configuration@EnableAutoConfiguration?和?@ComponentScan?三個注解的功能。

  • 作用
    • @Configuration:表明該類是一個配置類,相當于傳統 Spring 中的 XML 配置文件。
    • @EnableAutoConfiguration:開啟 Spring Boot 的自動配置功能,Spring Boot 會根據類路徑下的依賴和配置自動配置應用。
    • @ComponentScan:指定 Spring 掃描組件的范圍,默認掃描主應用類所在包及其子包下帶有?@Component@Service@Repository@Controller?等注解的類。
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class MySpringBootApp {public static void main(String[] args) {SpringApplication.run(MySpringBootApp.class, args);}
}

1.2?@EnableAutoConfiguration

  • 作用:Spring Boot 會根據類路徑中的依賴自動配置應用。例如,如果類路徑中存在 H2 數據庫的依賴,Spring Boot 會自動配置一個嵌入式的 H2 數據庫。不過,有時候自動配置可能不符合我們的需求,這時可以使用?exclude?屬性排除某些自動配置類。
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class MyAppWithoutDataSourceAutoConfig {public static void main(String[] args) {SpringApplication.run(MyAppWithoutDataSourceAutoConfig.class, args);}
}

1.3?@Configuration

  • 作用:用于定義配置類,配置類可以包含多個?@Bean?注解的方法,這些方法會返回一個對象,該對象會被 Spring 容器管理。
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;@Configuration
public class AppConfig {@Beanpublic List<String> myList() {return new ArrayList<>();}
}

1.4?@ComponentScan

  • 作用:指定 Spring 掃描組件的范圍。可以通過?basePackages?屬性指定要掃描的包,也可以通過?basePackageClasses?指定要掃描的類所在的包。
  • 示例
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;@Configuration
@ComponentScan(basePackages = "com.example.demo.service")
public class AppConfig {// 配置類內容
}

二、依賴注入與組件管理注解

2.1?@Component

  • 作用:這是一個通用的組件注解,用于標記一個類為 Spring 組件,被 Spring 容器管理。它是?@Service@Repository@Controller?的父注解。
  • 示例
import org.springframework.stereotype.Component;@Component
public class MyComponent {public void doSomething() {System.out.println("Doing something in MyComponent");}
}

2.2?@Service

  • 作用:通常用于標記業務邏輯層的類,是?@Component?的一種特殊形式,語義上更明確表示這是一個服務類。
  • 示例
import org.springframework.stereotype.Service;@Service
public class UserService {public void saveUser() {// 保存用戶的業務邏輯}
}

2.3?@Repository

  • 作用:主要用于標記數據訪問層的類,如 DAO 類。Spring 會自動處理?@Repository?注解類拋出的異常,將其轉換為 Spring 的數據訪問異常。
  • 示例
import org.springframework.stereotype.Repository;@Repository
public class UserRepository {public void saveUserToDb() {// 將用戶保存到數據庫的邏輯}
}

2.4?@Controller

  • 作用:用于標記控制器類,處理 HTTP 請求。通常與?@RequestMapping?等注解配合使用。
  • 示例
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;@Controller
public class MyController {@RequestMapping("/hello")@ResponseBodypublic String sayHello() {return "Hello, World!";}
}

2.5?@RestController

  • 作用:是?@Controller?和?@ResponseBody?的組合注解,用于創建 RESTful 風格的控制器,方法返回的對象會自動轉換為 JSON 或 XML 等格式返回給客戶端。
  • 示例
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class MyRestController {@GetMapping("/data")public String getData() {return "{\"message\": \"This is some data\"}";}
}

2.6?@Autowired

  • 作用:用于自動裝配 Bean,默認按照類型進行裝配。可以用于構造器、字段、方法上。
  • 示例
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class UserService {private UserRepository userRepository;@Autowiredpublic UserService(UserRepository userRepository) {this.userRepository = userRepository;}public void saveUser() {userRepository.saveUserToDb();}
}

2.7?@Qualifier

  • 作用:當存在多個相同類型的 Bean 時,@Autowired?無法確定要注入哪個 Bean,此時可以使用?@Qualifier?指定要注入的 Bean 的名稱。
  • 示例
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;@Service
public class MyService {private MyComponent myComponent;@Autowiredpublic MyService(@Qualifier("specificComponent") MyComponent myComponent) {this.myComponent = myComponent;}
}

2.8?@Resource

  • 作用:也是用于依賴注入,默認按照名稱進行裝配,如果找不到匹配的名稱,則按照類型進行裝配。
  • 示例
import javax.annotation.Resource;
import org.springframework.stereotype.Service;@Service
public class MyService {@Resourceprivate MyComponent myComponent;public void doSomething() {myComponent.doSomething();}
}

2.9?@Value

  • 作用:用于從配置文件中讀取屬性值并注入到 Bean 的字段中。支持 SpEL 表達式。
  • 示例
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component
public class MyConfig {@Value("${app.name}")private String appName;public String getAppName() {return appName;}
}

三、Web 開發相關注解

3.1?@RequestMapping

  • 作用:用于映射 HTTP 請求到控制器的處理方法上。可以指定請求的 URL、請求方法(GET、POST 等)、請求參數等。
  • 示例
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;@Controller
public class MyController {@RequestMapping(value = "/hello", method = RequestMethod.GET)@ResponseBodypublic String sayHello() {return "Hello, World!";}
}

3.2?@GetMapping@PostMapping@PutMapping@DeleteMapping@PatchMapping

  • 作用:這些注解是?@RequestMapping?的簡化形式,分別對應 HTTP 的 GET、POST、PUT、DELETE、PATCH 請求方法。
  • 示例
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class MyRestController {@GetMapping("/data")public String getData() {return "{\"message\": \"This is some data\"}";}
}

3.3?@PathVariable

  • 作用:用于獲取 URL 中的路徑變量。
  • 示例
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;@RestController
public class UserController {@GetMapping("/users/{id}")public String getUser(@PathVariable Long id) {return "User with ID: " + id;}
}

3.4?@RequestParam

  • 作用:用于獲取 HTTP 請求中的查詢參數。
  • 示例
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;@RestController
public class SearchController {@GetMapping("/search")public String search(@RequestParam String keyword) {return "Searching for: " + keyword;}
}

3.5?@RequestBody

  • 作用:用于將 HTTP 請求的主體內容綁定到方法的參數上,通常用于處理 JSON 或 XML 格式的數據。
  • 示例
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;@RestController
public class UserController {@PostMapping("/users")public String createUser(@RequestBody User user) {// 處理用戶創建邏輯return "User created: " + user.getName();}
}class User {private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}
}

3.6?@RequestHeader

  • 作用:用于獲取 HTTP 請求的頭部信息。
  • 示例
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;@RestController
public class HeaderController {@GetMapping("/headers")public String getHeader(@RequestHeader("User-Agent") String userAgent) {return "User-Agent: " + userAgent;}
}

3.7?@CookieValue

  • 作用:用于獲取 HTTP 請求中的 Cookie 值。
  • 示例
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RestController;@RestController
public class CookieController {@GetMapping("/cookies")public String getCookie(@CookieValue("session_id") String sessionId) {return "Session ID: " + sessionId;}
}

3.8?@ModelAttribute

  • 作用:有兩種使用方式。一是用于方法上,該方法會在控制器的每個處理方法執行前被調用,用于初始化一些數據;二是用于方法參數上,將請求參數綁定到一個對象上。
  • 示例
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RestController;@RestController
public class ModelAttributeController {@ModelAttributepublic void addAttributes(Model model) {model.addAttribute("message", "This is a pre - added message");}@GetMapping("/model")public String getModel(@ModelAttribute("message") String message) {return message;}
}

3.9?@SessionAttributes

  • 作用:用于將模型中的屬性存儲到會話中,以便在多個請求之間共享數據。
  • 示例
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.annotation.RestController;@RestController
@SessionAttributes("user")
public class SessionAttributeController {@GetMapping("/addUser")public String addUserToSession(Model model) {model.addAttribute("user", "John Doe");return "User added to session";}@GetMapping("/getUser")public String getUserFromSession(@ModelAttribute("user") String user) {return "User from session: " + user;}
}

四、數據訪問與事務管理注解

4.1?@Entity

  • 作用:用于標記一個 Java 類為 JPA 實體類,該類會映射到數據庫中的一張表。
  • 示例
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;@Entity
public class User {@Id@GeneratedValue(strategy = GenerationType.IDENTITY)private Long id;private String name;// Getters and Setters
}

4.2?@Table

  • 作用:用于指定實體類對應的數據庫表名。
  • 示例
import javax.persistence.Entity;
import javax.persistence.Table;@Entity
@Table(name = "users")
public class User {// 實體類內容
}

4.3?@Id

  • 作用:用于標記實體類中的主鍵字段。
  • 示例:見?@Entity?示例。

4.4?@GeneratedValue

  • 作用:用于指定主鍵的生成策略,如自增、UUID 等。
  • 示例:見?@Entity?示例。

4.5?@Column

  • 作用:用于指定實體類的字段與數據庫表列的映射關系,可設置列名、長度、是否可為空等屬性。
  • 示例
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;@Entity
public class User {@Idprivate Long id;@Column(name = "user_name", length = 50, nullable = false)private String name;// Getters and Setters
}

4.6?@Repository

  • 作用:在數據訪問層使用,標記該類為數據訪問組件,Spring 會自動處理數據訪問異常。
  • 示例
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;@Repository
public interface UserRepository extends JpaRepository<User, Long> {// 自定義查詢方法
}

4.7?@Transactional

  • 作用:用于聲明事務邊界,可以應用在類或方法上。在方法上使用時,該方法會在事務中執行;在類上使用時,該類的所有公共方法都會在事務中執行。可以設置事務的傳播行為、隔離級別等屬性。
  • 示例
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;@Service
public class UserService {private UserRepository userRepository;public UserService(UserRepository userRepository) {this.userRepository = userRepository;}@Transactionalpublic void saveUser(User user) {userRepository.save(user);}
}

五、AOP 相關注解

5.1?@Aspect

  • 作用:用于標記一個類為切面類,該類中可以定義切點和通知。
  • 示例
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;@Aspect
@Component
public class LoggingAspect {@Pointcut("execution(* com.example.demo.service.*.*(..))")public void serviceMethods() {}@Before("serviceMethods()")public void beforeServiceMethod() {System.out.println("Before service method execution");}
}

5.2?@Pointcut

  • 作用:用于定義切點表達式,指定哪些方法會被切面攔截。
  • 示例:見?@Aspect?示例。

5.3?@Before

  • 作用:前置通知,在目標方法執行前執行。
  • 示例:見?@Aspect?示例。

5.4?@After

  • 作用:后置通知,在目標方法執行后執行,無論目標方法是否拋出異常。
  • 示例
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;@Aspect
@Component
public class LoggingAspect {@Pointcut("execution(* com.example.demo.service.*.*(..))")public void serviceMethods() {}@After("serviceMethods()")public void afterServiceMethod() {System.out.println("After service method execution");}
}

5.5?@AfterReturning

  • 作用:返回通知,在目標方法正常返回后執行,可以獲取目標方法的返回值。
  • 示例
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;@Aspect
@Component
public class LoggingAspect {@Pointcut("execution(* com.example.demo.service.*.*(..))")public void serviceMethods() {}@AfterReturning(pointcut = "serviceMethods()", returning = "result")public void afterServiceMethodReturning(Object result) {System.out.println("Service method returned: " + result);}
}

5.6?@AfterThrowing

  • 作用:異常通知,在目標方法拋出異常時執行,可以獲取異常信息。
  • 示例
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;@Aspect
@Component
public class LoggingAspect {@Pointcut("execution(* com.example.demo.service.*.*(..))")public void serviceMethods() {}@AfterThrowing(pointcut = "serviceMethods()", throwing = "ex")public void afterServiceMethodThrowing(Exception ex) {System.out.println("Service method threw exception: " + ex.getMessage());}
}

5.7?@Around

  • 作用:環繞通知,環繞目標方法執行,可以在目標方法執行前后進行增強處理,還可以控制目標方法是否執行。
  • 示例
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;@Aspect
@Component
public class LoggingAspect {@Pointcut("execution(* com.example.demo.service.*.*(..))")public void serviceMethods() {}@Around("serviceMethods()")public Object aroundServiceMethod(ProceedingJoinPoint joinPoint) throws Throwable {System.out.println("Before service method execution");Object result = joinPoint.proceed();System.out.println("After service method execution");return result;}
}

六、測試相關注解

6.1?@SpringBootTest

  • 作用:用于啟動 Spring Boot 應用的上下文進行測試,可以模擬完整的應用環境。
  • 示例
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;@SpringBootTest
public class MyServiceTest {@Autowiredprivate MyService myService;@Testpublic void testMyService() {myService.doSomething();}
}

6.2?@MockBean

  • 作用:用于在測試中創建 Mock 對象,替換 Spring 容器中的實際 Bean,方便進行單元測試。
  • 示例
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;import static org.mockito.Mockito.when;@SpringBootTest
public class UserServiceTest {@Autowiredprivate UserService userService;@MockBeanprivate UserRepository userRepository;@Testpublic void testSaveUser() {User user = new User();when(userRepository.save(user)).thenReturn(user);userService.saveUser(user);}
}

6.3?@WebMvcTest

  • 作用:用于測試 Spring MVC 控制器,只加載與控制器相關的組件,不加載整個應用上下文,提高測試效率。
  • 示例
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.web.servlet.MockMvc;import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;@WebMvcTest(MyController.class)
public class MyControllerTest {@Autowiredprivate MockMvc mockMvc;@Testpublic void testSayHello() throws Exception {mockMvc.perform(get("/hello")).andExpect(status().isOk()).andExpect(content().string("Hello, World!"));}
}

6.4?@DataJpaTest

  • 作用:用于測試 JPA 數據訪問層,自動配置嵌入式數據庫,只加載與 JPA 相關的組件。
  • 示例
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;import static org.junit.jupiter.api.Assertions.assertNotNull;@DataJpaTest
public class UserRepositoryTest {@Autowiredprivate UserRepository userRepository;@Testpublic void testSaveUser() {User user = new User();user.setName("John Doe");User savedUser = userRepository.save(user);assertNotNull(savedUser.getId());}
}

七、其他注解

7.1?@Conditional

  • 作用:根據條件決定是否創建 Bean。可以自定義條件類,實現?Condition?接口。
  • 示例
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;@Configuration
public class AppConfig {@Bean@Conditional(MyCondition.class)public MyBean myBean() {return new MyBean();}
}

7.2?@ConditionalOnClass

  • 作用:當類路徑中存在指定的類時,才會創建對應的 Bean。
  • 示例
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;@Configuration
public class AppConfig {@Bean@ConditionalOnClass(name = "com.example.SomeClass")public MyBean myBean() {return new MyBean();}
}

7.3?@ConditionalOnMissingBean

  • 作用:當容器中不存在指定類型的 Bean 時,才會創建對應的 Bean。
  • 示例
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ConditionalOnMissingBean;
import org.springframework.context.annotation.Configuration;@Configuration
public class AppConfig {@Bean@ConditionalOnMissingBean(MyBean.class)public MyBean myBean() {return new MyBean();}
}

7.4?@ConditionalOnProperty

  • 作用:根據配置文件中的屬性值決定是否創建 Bean。
  • 示例
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;@Configuration
public class AppConfig {@Bean@ConditionalOnProperty(name = "app.feature.enabled", havingValue = "true")public MyBean myBean() {return new MyBean();}
}

7.5?@Scheduled

  • 作用:用于創建定時任務,可指定任務的執行時間間隔、固定延遲等。
  • 示例
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;@Component
public class MyScheduledTask {@Scheduled(fixedRate = 5000)public void doTask() {System.out.println("Task executed every 5 seconds");}
}

7.6?@EnableScheduling

  • 作用:啟用 Spring 的定時任務功能,通常與?@Scheduled?配合使用。
  • 示例
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;@SpringBootApplication
@EnableScheduling
public class MyApp {public static void main(String[] args) {SpringApplication.run(MyApp.class, args);}
}

7.7?@EnableAsync

  • 作用:啟用 Spring 的異步方法調用功能,通常與?@Async?配合使用。
  • 示例
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;@SpringBootApplication
@EnableAsync
public class MyApp {public static void main(String[] args) {SpringApplication.run(MyApp.class, args);}
}

7.8?@Async

  • 作用:標記方法為異步方法,該方法會在單獨的線程中執行。
  • 示例
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;@Service
public class MyAsyncService {@Asyncpublic void doAsyncTask() {// 異步執行的任務}
}

7.9?@ConfigurationProperties

  • 作用:用于將配置文件中的屬性綁定到一個 Java 對象上。
  • 示例
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;@Component
@ConfigurationProperties(prefix = "app")
public class AppConfigProperties {private String name;private String version;// Getters and Setters
}

7.10?@EnableConfigurationProperties

  • 作用:啟用?@ConfigurationProperties?注解的類,通常在配置類上使用。
  • 示例
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;@Configuration
@EnableConfigurationProperties(AppConfigProperties.class)
public class AppConfig {// 配置類內容
}

以上涵蓋了 Spring Boot 中大部分常用的注解,理解和掌握這些注解可以幫助開發者更高效地開發 Spring Boot 應用。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/72061.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/72061.shtml
英文地址,請注明出處:http://en.pswp.cn/web/72061.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【語料數據爬蟲】Python爬蟲|批量采集征集意見稿數據(1)

前言 本文是該專欄的第5篇,后面會持續分享Python爬蟲采集各種語料數據的的干貨知識,值得關注。 在本文中,筆者將主要來介紹基于Python,來實現批量采集“征集意見稿”數據。同時,本文也是采集“征集意見稿”數據系列的第1篇。 采集相關數據的具體細節部分以及詳細思路邏輯…

企業招聘能力提升之道:突破困境,精準納才

企業招聘能力提升之道&#xff1a;突破困境&#xff0c;精準納才 在企業運營的廣袤版圖中&#xff0c;招聘工作無疑是一塊至關重要的拼圖。然而&#xff0c;不少企業在這片領域中舉步維艱&#xff0c;盡管投入了海量的時間與精力&#xff0c;收獲的成果卻不盡人意。面試環節仿…

AI對前端開發的沖擊

Cursor cursor新版本0.46版本號中有部分是改成了新布局其實 Agent 和 Edit 和 Composer 是一樣的&#xff0c;為了方便大家使用&#xff0c;我們把它們合并了&#xff0c;Edit 相當于普通模式下的 Composer&#xff0c;Agent 就是代理模式。 快捷鍵ctrli、ctrll、ctrlk 4o適合…

java中如何把json轉化的字符串再轉化成json格式

使用org.json庫 首先&#xff0c;確保你的項目中已經包含了org.json庫。如果你使用Maven&#xff0c;可以在pom.xml中添加以下依賴&#xff1a; <dependency><groupId>org.json</groupId><artifactId>json</artifactId><version>20210307…

泛型、泛型上限、泛型下限、泛型通配符

DAY8.1 Java核心基礎 泛型 Generics 是指在類定義時不指定類中信息的具體數據類型&#xff0c;而是用一個標識符來代替&#xff0c;當外部實例化對象時再指定具體的數據類型。 在定義類或者接口時不明確指定類中信息的具體數據類型&#xff0c;在實例化時再來指定具體的數據類…

Win10 下搭建免費的 FTP 服務器 FileZilla

一、概述 FileZilla 服務器是一個免費的開源FTP和FTPS服務器&#xff0c;是根據GNU通用公共許可證條款免費發布的開源軟件。FileZilla支持FTP、FTPS、SFTP等文件傳輸協議&#xff0c;相比其他FTP服務器&#xff0c;最大的優勢是FileZilla自由(免費)。 FileZilla的官網地址是&a…

C/C++中對字符處理的常用函數

C語言中的 ctype.h 頭文件提供了一系列字符分類和轉換函數&#xff0c;用于高效處理字符相關操作。這些函數通過接受 int 類型參數&#xff08;需為 unsigned char 或 EOF &#xff08;-1&#xff09;值&#xff09;&#xff0c;返回非零值表示條件正確&#xff0c;返回0表示錯…

雙指針算法介紹+算法練習(2025)

一、介紹雙指針算法 雙指針&#xff08;或稱為雙索引&#xff09;算法是一種高效的算法技巧&#xff0c;常用于處理數組或鏈表等線性數據結構。它通過使用兩個指針來遍歷數據&#xff0c;從而減少時間復雜度&#xff0c;避免使用嵌套循環。雙指針算法在解決諸如查找、排序、去重…

【每日八股】計算機網絡篇(四):HTTP

目錄 HTTP 與 HTTPS 的區別&#xff1f;HTTPS 加密與認證的過程&#xff1f;ClientHelloServerHello客戶端回應服務端回應 HTTPS 一定安全可靠嗎&#xff1f;HTTPS 狀態碼的含義&#xff1f;HTTP 緩存有哪些實現方式&#xff1f;HTTP 1.0、HTTP 1.1、HTTP 2.0 和 HTTP 3.0 的區…

TMS320F28P550SJ9學習筆記10:軟件模擬I2C通信_驅動1.3寸OLED

現在有了具體的I2C通信器件&#xff0c;一塊1.3寸OLED屏幕&#xff0c;今日嘗試移植配置一下: 本文主要講的是&#xff0c;使用軟件模擬I2C通信 文章提供測試代碼講解、完整工程下載、測試效果圖 目錄 前置文章&#xff1a; I2C通信引腳&#xff1a; 軟件I2C 引腳的初始化&am…

spring boot 發送郵件驗證碼

一、前置需求 1、準備郵箱 2、登錄授權碼 qq郵箱在–>設置–>賬號POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服務 開啟服務 二、發送郵件 1、簡單郵件 包含郵件標題、郵件正文 2、引入mail啟動器 <dependency><groupId>org.springframework.boot</groupI…

塔能科技:智能機箱,為城市安防 “智” 造堅實堡壘

在當今智慧城市建設的浪潮中&#xff0c;城市安防面臨著諸多挑戰。設備管理難&#xff0c;眾多分散的安防設備猶如一盤散沙&#xff0c;難以實現高效統一的管控&#xff1b;數據傳輸不穩定&#xff0c;關鍵時刻信息的延遲或丟失&#xff0c;可能導致嚴重后果。這些問題嚴重制約…

電商數據分析 電商平臺銷售數據分析 電商平臺數據庫設計 揭秘電商怎么做數據分析

《電商參謀數據分析平臺方案》&#xff08;28頁PPT&#xff09;是一套為電商行業量身定制的一體化解決方案&#xff0c;它通過全鏈路打通從數據獲取到分析的全過程&#xff0c;幫助電商企業實現精細化運營和市場機會的挖掘。該方案針對電商行業在數據獲取、加工整合及業務賦能方…

uniapp uview 1.0 跨域h5配置多個代理、如何請求接口

參考文章&#xff1a;uniapp uView1.0跨域h5配置多個代理 官方手冊&#xff1a;http 請求 項目中使用&#xff1a; 參考其他博主的文章是在manifest.json中配置代理&#xff0c;但在官方的手冊中是直接在script請求的&#xff0c;我嘗試請求了下沒問題&#xff0c;上線后也不…

MAVEN解決版本依賴沖突

文章目錄 一、依賴沖突概念1、什么是依賴沖突2、依賴沖突的原因3、如何解決依賴沖突 二、查看依賴沖突-maven-helper1、安裝2、helper使用1、conflicts的閱讀順序&#xff08;從下向上看&#xff09;2、dependencies as List的閱讀順序&#xff08;從下向上看&#xff09;3、de…

79.ScottPlot的MVVM實現 C#例子 WPF例子

如何通過數據綁定在 WPF 中實現動態圖像顯示 在 WPF 應用程序中&#xff0c;通過數據綁定實現動態圖像顯示是一種高效且優雅的方式。以下是一個簡單的教程&#xff0c;展示如何使用 ScottPlot.WPF 庫和 MVVM 模式來實現這一功能。 第一步&#xff1a;安裝必要的 NuGet 包 首…

簡單工廠 、工廠方法模式和抽象工廠模式

簡單工廠 、工廠方法模式和抽象工廠模式 1.模式性質與定位 簡單工廠:并非正式的設計模式(屬編程習慣),通過單一工廠類根據參數判斷創建不同產品,本質是將對象創建邏輯集中管理。 工廠方法:是標準的創建型設計模式,定義抽象創建接口,由子類決定實例化哪個具體產品類,…

熱圖回歸(Heatmap Regression)

熱圖回歸(Heatmap Regression)是一種常用于關鍵點估計任務的方法,特別是在人體姿態估計中。它的基本思想是通過生成熱圖來表示某個關鍵點在圖像中出現的概率或強度。以下是熱圖回歸的主要特點和工作原理: 主要特點 熱圖表示: 每個關鍵點對應一個熱圖,熱圖中的每個像素值…

Word 小黑第15套

對應大貓16 修改樣式集 導航 -查找 第一章標題不顯示 再選中文字 點擊標題一 修改標題格式 格式 -段落 -換行和分頁 勾選與下段同頁 添加腳注 &#xff08;腳注默認位于底部 &#xff09;在腳注插入文檔屬性&#xff1a; -插入 -文檔部件 -域 類別選擇文檔信息&#xff0c;域…

Java 大視界 -- Java 大數據在智能安防視頻摘要與檢索技術中的應用(128)

&#x1f496;親愛的朋友們&#xff0c;熱烈歡迎來到 青云交的博客&#xff01;能與諸位在此相逢&#xff0c;我倍感榮幸。在這飛速更迭的時代&#xff0c;我們都渴望一方心靈凈土&#xff0c;而 我的博客 正是這樣溫暖的所在。這里為你呈上趣味與實用兼具的知識&#xff0c;也…