JavaEE——Spring4--(6)静态、实例工厂方法创建Bean

 

 

实现FactoryBean接口在Spring IOC容器中配置Bean

基于注解的方式配置Bean

组件扫描(component scanning): Spring 能够从 classpath 下自动扫描, 侦测和实例化具有特定注解的组件.
特定组件包括:
  @Component: 基本注解, 标识了一个受 Spring 管理的组件
  @Respository: 标识持久层组件
  @Service: 标识服务层(业务层)组件
  @Controller: 标识表现层组件
对于扫描到的组件, Spring 有默认的命名策略: 使用非限定类名, 第一个字母小写. 也可以在注解中通过 value 属性值标识组件的名称

 

 

<context:component-scan> 元素还会自动注册 AutowiredAnnotationBeanPostProcessor 实例,

该实例可以自动装配具有 @Autowired @Resource 、@Inject注解的属性. 

  @Autowired 注解自动装配具有兼容类型的单个 Bean属性

 

posted @ 2018-01-15 20:30  SkyeAngel  阅读(376)  评论(0编辑  收藏  举报