注解方式使用spring IOC容器,AnnotationConfigApplicationContext类的构造方法中的refresh方法的执行会触发regiter方法,但我没找到在哪里被调用的,求大佬解答
AnnotationConfigApplicationContext
的构造方法不是已经写了吗,“将注解方式的类解析成BeanDefinition
,然后注册到容器中”这个操作是在refresh()之前。
/\*\*
\* Create a new AnnotationConfigApplicationContext, deriving bean definitions \* from the given annotated classes and automatically refreshing the context. \* @param annotatedClasses one or more annotated classes,
\* e.g. {@link Configuration @Configuration} classes
\*/
public AnnotationConfigApplicationContext(Class<?\>... annotatedClasses) {
this();
register(annotatedClasses);
refresh();
}
/\*\*
\* Create a new AnnotationConfigApplicationContext, scanning for bean definitions \* in the given packages and automatically refreshing the context. \* @param basePackages the packages to check for annotated classes
\*/
public AnnotationConfigApplicationContext(String... basePackages) {
this();
// 这里面包含了扫描、解析和注册
scan(basePackages);
refresh();
}
评论 (6)