Spring ioc容器-BeanDefinition

IOC容器的初始化包括:

1、BeanDefinition的resource定位

2、BeanDefinition的载入和解析

3、BeanDefinition的注册

BeanDefinition的重要参数解析

public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
  /**
     * Return the bean names that this bean depends on.
     */
    String[] getDependsOn();
  /**
     * Set the names of the beans that this bean depends on being initialized.
     * The bean factory will guarantee that these beans get initialized first.
     */
    void setDependsOn(String[] dependsOn);
  /**
     * Return whether this a <b>Singleton</b>, with a single, shared instance
     * returned on all calls.
     * @see #SCOPE_SINGLETON
     */
    boolean isSingleton();

  /**
  * Return whether this bean is a candidate for getting autowired into some other bean.
   */
  boolean isAutowireCandidate();


  /**
  * Set whether this bean is a candidate for getting autowired into some other bean.
  */
  void setAutowireCandidate(boolean autowireCandidate)

}

 

1、BeanDefinition的resource定位

protected Resource getResourceByPath(String path) {
        if (path != null && path.startsWith("/")) {
            path = path.substring(1);
        }
        return new FileSystemResource(path);
    }
public class FileSystemResource extends AbstractResource implements WritableResource {

    private final File file;

    private final String path;
/**
     * Create a new FileSystemResource from a file path.
     * <p>Note: When building relative resources via {@link #createRelative},
     * it makes a difference whether the specified resource base path here
     * ends with a slash or not. In the case of "C:/dir1/", relative paths
     * will be built underneath that root: e.g. relative path "dir2" ->
     * "C:/dir1/dir2". In the case of "C:/dir1", relative paths will apply
     * at the same directory level: relative path "dir2" -> "C:/dir2".
     * @param path a file path
     */
    public FileSystemResource(String path) {
        Assert.notNull(path, "Path must not be null");
        this.file = new File(path);
        this.path = StringUtils.cleanPath(path);
    }

}

 

posted @ 2016-03-14 23:37  程序猿进化之路  阅读(107)  评论(0)    收藏  举报