Class<?>
是使用未綁定通配符的泛型類型。它的意思是「Class<Foo>
某些類型的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);
}
我正在尋找關於這個javadoc的進一步闡述。在ClasspathXmlApplicationContext的上下文中,這意味着什麼類型的資源?這裏「相對於給定班級」是什麼意思?請詳細說明,最好有一些例子或參考文件。 謝謝您的回覆! – Forumer