Spring-装配Bean 基于注解
2017-09-27 09:24
441 查看
注解:就是一个类,使用@注解名称
开发中:使用注解 取代 xml配置文件。
@Component取代
@Component(“id”) 取代
2.web开发,提供3个@Component注解衍生注解(功能一样)取代
@Repository :dao层
@Service:service层
@Controller:web层
3.依赖注入 ,给私有字段设置,也可以给setter方法设置
普通值:@Value(“”)
引用值:
方式1:按照【类型】注入
@Autowired
方式2:按照【名称】注入1
@Autowired
@Qualifier(“名称”)
方式3:按照【名称】注入2
@Resource(“名称”)
4.生命周期
初始化:@PostConstruct
销毁:@PreDestroy
5.作用域
@Scope(“prototype”) 多例
注解使用前提,添加命名空间,让spring扫描含有注解类
开发中:使用注解 取代 xml配置文件。
@Component取代
@Component(“id”) 取代
2.web开发,提供3个@Component注解衍生注解(功能一样)取代
@Repository :dao层
@Service:service层
@Controller:web层
3.依赖注入 ,给私有字段设置,也可以给setter方法设置
普通值:@Value(“”)
引用值:
方式1:按照【类型】注入
@Autowired
方式2:按照【名称】注入1
@Autowired
@Qualifier(“名称”)
方式3:按照【名称】注入2
@Resource(“名称”)
4.生命周期
初始化:@PostConstruct
销毁:@PreDestroy
5.作用域
@Scope(“prototype”) 多例
注解使用前提,添加命名空间,让spring扫描含有注解类
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 组件扫描,扫描含有注解的类 --> <context:component-scan base-package="com.itheima.g_annotation.a_ioc"></context:component-scan> </beans>
相关文章推荐
- spring-装配Bean 基于注解
- Spring装配bean基于XML,注解
- Spring中 基于注解的装配Bean 与 基于xml的对比总结
- [原创]java WEB学习笔记103:Spring学习---Spring Bean配置:基于注解的方式(基于注解配置bean,基于注解来装配bean的属性)
- Spring(七)基于注解装配bean
- Spring 装配Bean 基于注解
- 【JavaWeb-23】spring、IoC控制反转和DI依赖注入入门、基于XML的Bean装配、基于注解的Bean装配
- 【Java.Spring.Core】【IoC】基于注解的Bean装配(非XML配置)
- spring、IoC控制反转和DI依赖注入入门、基于XML的Bean装配、基于注解的Bean装配
- Spring基于注解装配bean
- Spring-Bean之基于注解(Annotation)装配解析
- 框架 day36 Spring3 入门,DI依赖注入,装配bean基于xml/注解, 整合Junit4,配置约束自动提示
- Spring In Action(一):基于注解装配bean
- Spring(3、基于注解装配Bean)
- spring实战-注解装配bean
- Spring Bean装配之Autowired注解说明-1
- spring注解装配bean简单例子
- Spring 框架 详解 (四)------IOC装配Bean(注解方式)
- Spring学习:bean的自动装配(注解)
- Spring中我们用到的功能实现:基于注解的Ioc自动装配