Spring注解模块

Spring注解模块,第1张

Spring注解模块

目录

IOC / DI  注解

AOP注解


IOC / DI  注解

@Configuration 标识配置类

@Bean 将对象交给spring容器管理 方法标识

@Component 将当前类交给spring容器管理,通过反射机制自动完成对象的创建

@Repository  与@component同义, 在mapper/dao层 使用

@Mapper  与@component同义,为体现分层思想  在mapper/dao层 使用

@Service  与@component同义,为体现分层思想  在service层使用

@Controller  与@component同义,为体现分层思想  在controller层使用

@componentscan 后加路径,扫描@component注解的类

@Scope 默认为 单例模式

@Scope("singleton") 单例模式

@Scope("prototype") 多例模式

@lazy 懒加载,当对象使用时才会创建对象 只对单例模式有效 多例默认懒加载

@PostConstruct 标识该方法在对象创建之后立即调用

@PreDestroy 标识该方法在对象消亡时调用

@Autowired 将spring容器中的对象,自动注入到属性中; 默认按照类型注入,如果注入的属性是接口,则自动注入实现类

@Qualifire("xx") 与@Autowired一起使用, 该注解用于多实现,指定注入对象

@Resource("xx") @Autowired与@Qualifire("xx") 注解的结合体, 但并不是spring提供的

@Value("xxx") 该注解可以直接为 基本类型 赋值

AOP注解

@EnableAspectJAutoProxy 开启AOP

@Aspect 标识该类为切面

@PointCut("bean(bean ID)") 切入点表达式 标记一个方法,通常写为 pointCut();  用于五个通知方法

@Before("pointCut()") 前置通知,目标方法执行前执行

@AfterReturning("pointCut()") 后置通知, 目标方法执行后执行

@After("pointCut()")  异常通知, 目标方法报错后执行

@AfterThrowing("pointCut()")  最终通知,只要执行目标方法,该通知就会执行

@Around("pointCut()")   环绕通知 可控制目标方法执行的通知

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5708221.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存