-
【后端】Spring注解开发
注意 :必须开启注解的支持 让注解生效(在 applicationContext.xml 中配置)
|
|
|
@Autowired
自动装配通过类型、名字匹配
@Qualifier
如果@Autowired不能唯一自动装配上属性(多个不同id的bean标签对应同一个类)
则需要通过 @Qualifier(value = "xxx")
@Nullable
字段标记了这个注解 说明这个字段可以为Null
@Resource
自动装配通过名字、类型匹配
|
@Component
组件 说明这个类被Spring管理了 是Bean
在web开发中 按照MVC三层架构开发
-
dao ->
@Repository
-
service ->
@Service
-
controller ->
@Controller
这四个注解功能一样 都是将某个类注册到Spring中 装配Bean
|
@Scope
|
|
|
|
@Aspect
标注这个类是一个切面
@After
相当于 <aop:After method="method" pointcut-ref="pointcut"/>
@Before
相当于 <aop:before method="method" pointcut-ref="pointcut"/>
@Around
相当于 <aop:around method="method" pointcut-ref="pointcut"/>
@AfterReturning
相当于 <aop:after-returning method="method" pointcut-ref="pointcut"/>
@AfterThrowing
相当于 <aop:after-throwing method="method" pointcut-ref="pointcut"/>
|
|
- XML适用于任何场合!维护简单方便
- 注解不是自己的类无法使用 维护相对复杂
|
- XML用来管理bean;
- 注解只负责完成属性的注入
|
Spring Framework Documentation
|
【狂神说Java】Spring5最新完整教程IDEA版通俗易懂_哔哩哔哩_bilibili
|
本文作者:双份浓缩馥芮白
原文链接:https://www.cnblogs.com/Flat-White/p/15110606.html
版权所有,如需转载请注明出处。