<select id="selectUserInfo" resultType="springboot.strategy.entity.User"> SELECT * FROM user WHERE user_name is not null order by create_time desc </select> </mapper>
/** * @author zhaokk * @create 2023-03-27 11:45 */ @Component public class SpringFactoriesLoaderExtend{
/** * The location to look for factories. * <p>Can be present in multiple JAR files. */ public static final String FACTORIES_RESOURCE_LOCATION = "META-INF/spring.factories";
private static final Log logger = LogFactory.getLog(SpringFactoriesLoader.class);
//private static final Map<ClassLoader, MultiValueMap<String, String>> cache = new ConcurrentReferenceHashMap<>();
private SpringFactoriesLoaderExtend() { }
/** * Load and instantiate the factory implementations of the given type from * {@value #FACTORIES_RESOURCE_LOCATION}, using the given class loader. * <p>The returned factories are sorted through {@link AnnotationAwareOrderComparator}. * <p>If a custom instantiation strategy is required, use {@link #loadFactoryNames} * to obtain all registered factory names. * @param factoryClass the interface or abstract class representing the factory * @param classLoader the ClassLoader to use for loading (can be {@code null} to use the default) * @throws IllegalArgumentException if any factory implementation class cannot * be loaded or if an error occurs while instantiating any factory * @see #loadFactoryNames */ public static <T> List<T> loadFactories(Class<T> factoryClass, @Nullable ClassLoader classLoader) { Assert.notNull(factoryClass, "'factoryClass' must not be null"); ClassLoader classLoaderToUse = classLoader; if (classLoaderToUse == null) { classLoaderToUse = SpringFactoriesLoader.class.getClassLoader(); } List<String> factoryNames = loadFactoryNames(factoryClass, classLoaderToUse); if (logger.isTraceEnabled()) { logger.trace("Loaded [" + factoryClass.getName() + "] names: " + factoryNames); } List<T> result = new ArrayList<>(factoryNames.size()); for (String factoryName : factoryNames) { result.add(instantiateFactory(factoryName, factoryClass, classLoaderToUse)); } AnnotationAwareOrderComparator.sort(result); return result; }
/** * Load the fully qualified class names of factory implementations of the * given type from {@value #FACTORIES_RESOURCE_LOCATION}, using the given * class loader. * @param factoryClass the interface or abstract class representing the factory * @param classLoader the ClassLoader to use for loading resources; can be * {@code null} to use the default * @throws IllegalArgumentException if an error occurs while loading factory names * @see #loadFactories */ public static List<String> loadFactoryNames(Class<?> factoryClass, @Nullable ClassLoader classLoader) { String factoryClassName = factoryClass.getName(); Collection<List<String>> values = loadSpringFactories(classLoader, factoryClassName).values(); List<String> names = new ArrayList<>(); for (List<String> value : values) { for (String s : value) { names.add(s); } } Collection<List<String>> values1 = loadSpringFactories(classLoader, factoryClassName).values(); List<String> collect = values1.stream().filter(item -> item.size() > 1).flatMap(set -> set.stream()).collect(Collectors.toList()); return names; }
private static Map<String, List<String>> loadSpringFactories(@Nullable ClassLoader classLoader,String className) { MultiValueMap<String, String> result = new LinkedMultiValueMap<>(); try { Enumeration<URL> urls = classLoader.getResources(FACTORIES_RESOURCE_LOCATION); result = new LinkedMultiValueMap<>(); while (urls.hasMoreElements()) { if (!result.isEmpty()) { break; } URL url = urls.nextElement(); UrlResource resource = new UrlResource(url); Properties properties = PropertiesLoaderUtils.loadProperties(resource); for (Map.Entry<?, ?> entry : properties.entrySet()) {
ApplicationContext 实例化所有剩余的(非惰性init)singleton →org.springframework.boot.SpringApplication#refreshContext →→org.springframework.context.support.AbstractApplicationContext#refresh →→→org.springframework.context.support.AbstractApplicationContext#finishBeanFactoryInitialization initializing all remaining singleton beans protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) { // Initialize conversion service for this context. if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME) && beanFactory.isTypeMatch(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)) { beanFactory.setConversionService( beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)); }
// Register a default embedded value resolver if no bean post-processor // (such as a PropertyPlaceholderConfigurer bean) registered any before: // at this point, primarily for resolution in annotation attribute values. if (!beanFactory.hasEmbeddedValueResolver()) { beanFactory.addEmbeddedValueResolver(strVal -> getEnvironment().resolvePlaceholders(strVal)); }
// Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early. String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false); for (String weaverAwareName : weaverAwareNames) { getBean(weaverAwareName); }
// Stop using the temporary ClassLoader for type matching. beanFactory.setTempClassLoader(null); //冻结所有的beanDefinition // Allow for caching all bean definition metadata, not expecting further changes. beanFactory.freezeConfiguration();
// Instantiate all remaining (non-lazy-init) singletons. beanFactory.preInstantiateSingletons(); }
public static Class<? extends WmsDailySettlementService> getClazz(Integer param) { if (StringUtils.isEmpty(param)) { throw new NullPointerException("param is null"); } else { for (DynamicStrategyEnum strategyEnum : DynamicStrategyEnum.values()) { if (strategyEnum.getCode().equals(param)) { return strategyEnum.getClazz(); } } throw new NullPointerException(String.format("param is null is %s", param)); } } }