天天看點

Spring中常用注解

  1. @Component 建立類對象,相當于配置

    <bean/>

  2. @Service 與@Component 功能相同

    2.1 寫在 ServiceImpl 類上

  3. @Repository 與@Component 功能相同

    3.1 寫在資料通路層類上

  4. @Controller 與@Component 功能相同
  5. 1 寫在控制器類上
  6. @Resource(不需要寫對象的 get/set)

    5.1 java 中的注解

    5.2 預設按照 byName 注入,如果沒有名稱對象,按照 byType 注入

    5.2.1 建議把對象名稱和 spring 容器中對象名相同

  7. @Autowired(不需要寫對象的 get/set)
  8. 1 spring 的注解
  9. 2 預設按照 byType 注入
  10. @Value() 擷取 properties 檔案中内容
  11. @Pointcut() 定義切點
  12. @Aspect() 定義切面類
  13. @Before() 前置通知
  14. @After 後置通知
  15. @AfterReturning 後置通知,必須切點正确執行
  16. @AfterThrowing 異常通知
  17. @Arround 環繞通知