ClassPathXmlApplicationContext中的第二个参数是什么(String path,Class <! - ? - > clazz)

时间:2017-10-14 03:00:14

标签: xml spring

请帮助我理解这种方法的Javadocs。第二个参数如何影响返回的上下文?

  

这是一种相对于加载类路径资源的便捷方法   给定的类。为了充分灵活,请考虑使用a   带有XmlBeanDefinitionReader和a的GenericApplicationContext   ClassPathResource参数。

1 个答案:

答案 0 :(得分:0)

Class<?>是使用未绑定通配符的泛型类型。对于某种类型的Foo来说,它意味着“Class<Foo>”。 ClassPathXmlApplicationContext 构造函数参数clazz使类加载资源(给定路径的基础)。

/**
 * Create a new ClassPathXmlApplicationContext, loading the definitions
 * from the given XML file and automatically refreshing the context.
 * <p>This is a convenience method to load class path resources relative to a
 * given Class. For full flexibility, consider using a GenericApplicationContext
 * with an XmlBeanDefinitionReader and a ClassPathResource argument.
 * @param path relative (or absolute) path within the class path
 * @param clazz the class to load resources with (basis for the given paths)
 * @throws BeansException if context creation failed
 * @see org.springframework.core.io.ClassPathResource#ClassPathResource(String, Class)
 * @see org.springframework.context.support.GenericApplicationContext
 * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
 */
public ClassPathXmlApplicationContext(String path, Class clazz) throws BeansException {
    this(new String[] {path}, clazz);
}
相关问题