getFactory()方法返回一个Factory
首先从系统属性获取factory的实现类名,没有则继续
String factoryClass = getSystemProperty(FACTORY_PROPERTY, null);
public static final String FACTORY_PROPERTY = "org.apache.commons.logging.LogFactory";
通过JDK1.3的Service Discovery机制 查找factory的实现类名,没有则继续
final InputStream is = getResourceAsStream(contextClassLoader, SERVICE_ID);
protected static final String SERVICE_ID = "META-INF/services/org.apache.commons.logging.LogFactory";
查找配置文件
commons-logging.properties
中的属性
org.apache.commons.logging.LogFactory
来查找factory的实现类名,没有则继续
Properties props = getConfigurationFile(contextClassLoader, FACTORY_PROPERTIES);
public static final String FACTORY_PROPERTIES = "commons-logging.properties";
String factoryClass = props.getProperty(FACTORY_PROPERTY);
public static final String FACTORY_PROPERTY = "org.apache.commons.logging.LogFactory";
最后如果以上3个都没找到,采用
org.apache.commons.logging.impl.LogFactoryImpl
factory = newFactory(FACTORY_DEFAULT, thisClassLoader, contextClassLoader);
public static final String FACTORY_DEFAULT = "org.apache.commons.logging.impl.LogFactoryImpl";
时间: 2024-11-08 14:15:06