走向自动装配
一.Spring Framework手动装配
1.Spring模式注解装配
- 定义:一种用于声明在应用中扮演”组件“角色的注解
- 举例:@Component、@Service、@Configuration等
- 装配:
<context:component-scan>
或@ComponentScan
2.模式注解
- 模式注解是一种用于声明在应用中扮演”组件“角色的注解
- 模式注解举例
Spring Framework注解 | 场景说明 | 起始版本 |
---|---|---|
@Repository | 数据仓库模式注解(常用于注解Dao) | 2.0 |
@Component | 通用组件模式注解 | 2.5 |
@Service | 服务模式注解 | 2.5 |
@Controller | Web控制器模式注解 | 2.5 |
@Configuration | 配置类模式注解 | 3.0 |
3.装配方式
- @ComponentScan方式
@ComponentScan(basePackages="扫描包名")
public class SpringConfiguration {
...
}
4.自定义模式注解
未完待续…