1: Lista para a matriz
1.1: Ferramentas
org.springframework.util.StringUtils
。
1.2: Caso de uso
private List<String> filter(List<String> configurations, AutoConfigurationMetadata autoConfigurationMetadata) {
...
String[] candidates = StringUtils.toStringArray(configurations);
}
2: Carregar META-INF/spring.factories
dados
SpringFactoriesLoader.loadFactoryNames({class 全限定名}, {类加载器});
,Tal como:
List<String> configurations = SpringFactoriesLoader.loadFactoryNames(getSpringFactoriesLoaderFactoryClass(), getBeanClassLoader());
3: Lista de desduplicação
protected final <T> List<T> removeDuplicates(List<T> list) {
return new ArrayList<>(new LinkedHashSet<>(list));
}
4: Verifique se uma determinada classe existe no caminho de classe
4.1: Ferramentas
org.springframework.util.ClassUtils
。
4.2: Caso de uso
ClassUtils.isPresent("org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration", getClass().getClassLoader())
5: Converta uma string separada por vírgulas em uma matriz
5.1: Ferramentas
org.springframework.util.StringUtils
。
5.2: Caso de uso
// javax.servlet.Servlet,org.springframework.web.servlet.config.annotation.WebMvcConfigurer,org.springframework.web.servlet.DispatcherServlet
for (String candidate : StringUtils.commaDelimitedListToStringArray(candidates)) {
ConditionOutcome outcome = getOutcome(candidate, this.beanClassLoader);
if (outcome != null) {
return outcome;
}
}
6: Obtenha o carregador de classes usado atualmente
6.1: Ferramentas
org.springframework.util.ClassUtils
。
6.2: Caso de uso
public static boolean isPresent(String className, ClassLoader classLoader) {
if (classLoader == null) {
classLoader = ClassUtils.getDefaultClassLoader();
}
try {
forName(className, classLoader);
return true;
}
catch (Throwable ex) {
return false;
}
}
7: Converta a matriz em uma string separada por vírgulas
7.1: Ferramentas
org.springframework.util.StringUtils#arrayToDelimitedString
。
7.2: Caso de uso
public Builder andCondition(String condition, Object... details) {
Assert.notNull(condition, "Condition must not be null");
String detail = StringUtils.arrayToDelimitedString(details, " ");
if (StringUtils.hasLength(detail)) {
return new Builder(condition + " " + detail);
}
return new Builder(condition);
}
8: cópia da matriz
8.1: Ferramentas
java.lang.System#arraycopy
。
8.2: Caso de uso
ConditionOutcome[] secondHalf = secondHalfResolver.resolveOutcomes();
ConditionOutcome[] firstHalf = firstHalfResolver.resolveOutcomes();
ConditionOutcome[] outcomes = new ConditionOutcome[autoConfigurationClasses.length];
System.arraycopy(firstHalf, 0, outcomes, 0, firstHalf.length);
System.arraycopy(secondHalf, 0, outcomes, split, secondHalf.length);
Código-fonte anexado:
/*
src:源数组
srcPos:源数组拷贝的开始位置
dest:目标数组
destPos:拷贝到目标数组的开始位置
length:拷贝源数组的元素的个数
*/
public static native void arraycopy(Object src,
int srcPos,
Object dest,
int destPos,
int length);
9: Crie objetos com base na classe
9.1: Ferramentas
org.springframework.beans.BeanUtils#instantiateClass(java.lang.Class<T>)
。
9.2: Exemplos de uso
protected ConfigurableApplicationContext createApplicationContext() {
Class<?> contextClass = this.applicationContextClass;
if (contextClass == null) {
try {
switch (this.webApplicationType) {
case SERVLET:
contextClass = Class.forName(DEFAULT_SERVLET_WEB_CONTEXT_CLASS);
break;
case REACTIVE:
contextClass = Class.forName(DEFAULT_REACTIVE_WEB_CONTEXT_CLASS);
break;
default:
contextClass = Class.forName(DEFAULT_CONTEXT_CLASS);
}
}
catch (ClassNotFoundException ex) {
throw new IllegalStateException(
"Unable create a default ApplicationContext, " + "please specify an ApplicationContextClass",
ex);
}
}
return (ConfigurableApplicationContext) BeanUtils.instantiateClass(contextClass);
}
10: URI de conversão de URL
10.1: Ferramentas
org.springframework.util.ResourceUtils
。
10.2: Caso de uso
org.springframework.core.io.AbstractResource#getURI
@Override
publicURI getURI() throws IOException {
URL url = getURL();
try {
return ResourceUtils.toURI(url);
}
catch (URISyntaxException ex) {
throw new NestedIOException("Invalid URI [" + url + "]", ex);
}
}
11: O caminho de processamento é um formato padrão
11.1: Descrição da função
Processamento caminhos relativos ..
, .
e outras informações, remova como se segue ..
:
processamento barras:
11.2: Ferramentas
org.springframework.util.StringUtils#cleanPath
。
11.3: Caso de uso
org.springframework.core.io.FileSystemResource#FileSystemResource(java.lang.String)
public FileSystemResource(String path) {
Assert.notNull(path, "Path must not be null");
this.path = StringUtils.cleanPath(path);
this.file = new File(path);
this.filePath = this.file.toPath();
}
12: file:
Obtenha o objeto Arquivo por meio do URL do arquivo de protocolo
12.1: Ferramentas
org.springframework.util.ResourceUtils#getFile(java.net.URL, java.lang.String)
。
12.2: Caso de uso
org.springframework.core.io.AbstractFileResolvingResource#getFile()
@Override
public File getFile() throws IOException {
URL url = getURL();
if (url.getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) {
return VfsResourceDelegate.getResource(url).getFile();
}
return ResourceUtils.getFile(url, getDescription());
}
13: Determine se o caminho contém curingas
13.1: Ferramentas
org.springframework.util.AntPathMatcher#isPattern
。
13.1: Exemplos de uso
new AntPathMatcher().isPattern("yudaosourcecode/spring/*.class")
14: Carregar o arquivo .properties
14.1: Ferramentas
org.springframework.core.io.support.PropertiesLoaderUtils
。
14.2: Exemplos de uso
// META-INF/spring.schemas
Properties mappings = PropertiesLoaderUtils.loadAllProperties(this.schemaMappingsLocation, this.classLoader);
schemaMappings = new ConcurrentHashMap<>(mappings.size());
// 合并properties内容到map中
CollectionUtils.mergePropertiesIntoMap(mappings, schemaMappings);
this.schemaMappings = schemaMappings;
15: mesclar .properties no mapa
15.1: Ferramentas
org.springframework.util.CollectionUtils
。
15.2: Exemplos de uso
// META-INF/spring.schemas
Properties mappings = PropertiesLoaderUtils.loadAllProperties(this.schemaMappingsLocation, this.classLoader);
schemaMappings = new ConcurrentHashMap<>(mappings.size());
// 合并properties内容到map中
CollectionUtils.mergePropertiesIntoMap(mappings, schemaMappings);
16: Encontre o primeiro elemento que existe em outra coleção de uma coleção
16.1: Ferramentas
org.springframework.util.CollectionUtils#findFirstMatch
。
16.2: Caso de uso
org.springframework.beans.factory.xml.BeanDefinitionParserDelegate#checkNameUniqueness
protected void checkNameUniqueness(String beanName, List<String> aliases, Element beanElement) {
String foundName = null;
if (StringUtils.hasText(beanName) && this.usedNames.contains(beanName)) {
foundName = beanName;
}
if (foundName == null) {
foundName = CollectionUtils.findFirstMatch(this.usedNames, aliases);
}
if (foundName != null) {
error("Bean name '" + foundName + "' is already used in this <beans> element", beanElement);
}
this.usedNames.add(beanName);
this.usedNames.addAll(aliases);
}