spring常用注解
来源:互联网 发布:启明英语听说软件 编辑:程序博客网 时间:2024/06/07 06:56
Spring自带的@Component注解及扩展
@Component:定义Spring管理Bean
@AspectJ风格的切面可以通过@Compenent注解标识其为Spring管理Bean,而@Aspect注解不能被Spring自动识别并注册为Bean,必须通过@Component注解来完成
- @Component
- @Aspect
- public class TestAspect {
- @Pointcut(value="execution(* *(..))")
- private void pointcut() {}
- @Before(value="pointcut()")
- public void before() {
- System.out.println("=======before");
- }
- }
通过@Component将切面定义为Spring管理Bean。
@Repository:
@Component扩展,被@Repository注解的POJO类表示DAO层实现,从而见到该注解就想到DAO层实现,使用方式和@Component相同;
@Service:
@Component扩展,被@Service注解的POJO类表示Service层实现,从而见到该注解就想到Service层实现,使用方式和@Component相同;
@Controller:
@Component扩展,被@Controller注解的类表示Web层实现,从而见到该注解就想到Web层实现,使用方式和@Component相同;
在使用Spring代理时,默认只有在public可见度的方法的@Transactional 注解才是有效的,其它可见度(protected、private、包可见)的方法上即使有@Transactional 注解也不会应用这些事务属性的,Spring也不会报错,如果你非要使用非公共方法注解事务管理的话,可考虑使用AspectJ。
Spring声明式事务实现其实就是Spring AOP+线程绑定实现,利用AOP实现开启和关闭事务,利用线程绑定(ThreadLocal)实现跨越多个方法实现事务传播。
- 【spring ----- 注解篇】 常用注解
- spring常用注解
- Spring IOC 常用注解
- Spring常用注解方式
- Spring常用注解
- spring常用注解
- spring 常用注解集合
- Spring IOC 常用注解
- spring常用注解
- Spring常用注解
- Spring IoC常用注解
- spring常用注解
- Spring常用注解
- Spring常用注解
- spring mvc 常用注解
- spring常用注解
- Spring常用注解说明
- Spring常用注解
- [日推荐]『梦想旅行』出国旅行全攻略!
- 程序员设计的这些作品震惊UI界!
- 插入公式的方法有些麻烦WORD用域如何直接输入分数
- Java读取本地文件中字符
- JAVA数据库连接池实现
- spring常用注解
- Gym 101201F Illumination(2-sat)
- Learning Spark笔记13-Broadcast Variables(传播变量)
- 【PHP】PHP基础知识与C++、Java等C家族的重点区别
- 数据库的方向
- 按钮被点击后屏蔽点击且倒计时60S能再次被点击-JS实现和JQuery实现
- skynet底层源码阅读(3)-模块管理
- Unicode 和 UTF-8 到底有何区别?
- 利用阿里大于(大鱼)平台进行发送手机验证码