天天看点

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 环绕通知