5.spring_注解

1. spring注解整理
1.创建当前对象交给IOC容器
@Component(value="id"@Controller(value="id")
@Service(value="id")
@Repositoty(value="id")
注意:不写value,默认为id=当前对象类型,首字母小写

1.1 事务控制:@Transactional 

2.属性依赖注入
@Autowired 按照类型注入
@Qualifiter(value="id") 按照id注入 配合@AutoWired一起使用

@Qualifiter(value="id") 在方法参数中单独使用,从IOC容器获取一个对象,注入给参数对象。

@Value    
	@value(#{100})    使用占位符传值    注入基本数据类型 
    @Value("192.168") 使用字ognl表达式  注入String类型
 	@Value("${key}")  使用EL表达式      注入被spring容器管理的properties文件中的内容 
                                       properties文件必须被IOC容器加载过
 
@Resourse("id") JDK提供的,不建议使用 ==  @Autowired + @Qualifiter(value="id")

3.生命周期注解
@Scope(singleton|protoType)  配置在类上,单例/多例
@PostConstruct               配置在方法上,init执行
@PreDestroy                  配置在方法上,销毁前执行

4.springTest相关注解
@Runwith(SpringJunit4ClassRunner.class) 申明spring提供这个类,加载配置文件
@ContextConfiguration(locations="classPath:bean.xml") 申明spring的配置文件地址
@ContextCOnfiguration(classes= springConfig.class) 申明配置类 (全注解式开发)

    
5 纯注解编程(编写配置文件类)  (了解)
@Configuration:声明配置类
@ComponentScan(basePackages=SpringConfig.class): 开启包扫描
@PropertySource:将properties配置文件交给spring容器管理
@Import:引入其它的配置类
@Bean : 配置到方法上,表明此方法的返回值类对象交给spring容器管理

6.AOP注解
@Component + @Aspect //表示当前类为切面类
@pointcut("execution(* cn.itcast..save(..))") //抽取切入点方法注解 
@Before("pointcut()")  //前置通知 
@After-returning("pointcut()") //后置通知
@After-throwing("pointcut()")  //异常通知
@after("pointcut()")  //最终通知
@Around("pointcut()") //环绕通知

7.spring配置文件--配置类注解
@Configuration //实现配置类
@ComponentScan //实现注解扫描
@EnableAspectJAutoProxy //开启AOP注解使用  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值