Spring的常见注解及其作用:
1. @Component 创建类对象,相当于配置<bean/>
bean的ID默认为类名首字母小写,也可以指定ID,例如@Component("stu")
2. @Service 与@Component功能相同.
2.1 写在ServiceImpl类上.
3. @Repository 与@Component功能相同.
3.1 写在数据访问层类上.
4. @Controller 与@Component功能相同.
4.1 写在控制器类上.
5. @Resource(不需要写对象的get/set)
5.1 java中的注解
5.2 默认按照byName注入,如果没有名称对象,按照byType注入
5.2.1 建议把对象名称和spring容器中对象名相同
6. @Autowired(不需要写对象的get/set)
6.1 spring的注解
6.2 默认按照byType注入.
7. @Value() 获取properties文件中内容
-------------------------------------
8. @Pointcut() 定义切点
9. @Aspect() 定义切面类
10. @Before() 前置通知
11. @After 后置通知
12. @AfterReturning 后置通知,必须切点正确执行
13. @AfterThrowing 异常通知
14. @Arround 环绕通知
注意:
使用注解,一定要在配置文件中声明注解扫描
<context:component-scan base-package="包名路径"></context:component-scan>
Spring 中注解的支持
创建对象 :@Component @Service @Controller
进行值得注入: @Resource @Autowired
<context:component-scan base-package="com.bjsxt.service.impl"></context:component-scan>
AspectJ的注解: @Aspect @Befor ..
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
声明式事务注解 @Transactional
<tx:annotation-driven></tx:annotation-driven>