创建对象的
- @Component
- @Repository:持久层
- @Service:业务层
- @Controller:表现层
- @Bean:函数返回对象存入spring容器
注入数据
- @Autowired:自动根据类型注入,在spring容器中寻找,找到了则注入,找不到报错
- @Qualifier:对字段进行注入时,要与@Autowired搭配;对方法参数注入时单独使用
- @Resource:根据Bean 的id注入
- @Value:基本数据类型,String类型
范围与其他
- @scope:指定范围
- @PostConstruct:指定初始化函数
- @PreDestroy:指定销毁函数
配置
@Configuration:
@ComponentScan:对指定的包进行扫描
@PropertySource:.propreties文件
@import
读取配置:AnnotationConfigApplication
new AnnotationConfigApplicationContext(SpringConfiguration.class);