Java Code Examples for org.springframework.core.io.ResourceLoader#getClassLoader()

The following examples show how to use org.springframework.core.io.ResourceLoader#getClassLoader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParserStrategyUtils.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Invoke {@link BeanClassLoaderAware}, {@link BeanFactoryAware},
 * {@link EnvironmentAware}, and {@link ResourceLoaderAware} contracts
 * if implemented by the given object.
 */
public static void invokeAwareMethods(Object parserStrategyBean, Environment environment,
		ResourceLoader resourceLoader, BeanDefinitionRegistry registry) {

	if (parserStrategyBean instanceof Aware) {
		if (parserStrategyBean instanceof BeanClassLoaderAware) {
			ClassLoader classLoader = (registry instanceof ConfigurableBeanFactory ?
					((ConfigurableBeanFactory) registry).getBeanClassLoader() : resourceLoader.getClassLoader());
			if (classLoader != null) {
				((BeanClassLoaderAware) parserStrategyBean).setBeanClassLoader(classLoader);
			}
		}
		if (parserStrategyBean instanceof BeanFactoryAware && registry instanceof BeanFactory) {
			((BeanFactoryAware) parserStrategyBean).setBeanFactory((BeanFactory) registry);
		}
		if (parserStrategyBean instanceof EnvironmentAware) {
			((EnvironmentAware) parserStrategyBean).setEnvironment(environment);
		}
		if (parserStrategyBean instanceof ResourceLoaderAware) {
			((ResourceLoaderAware) parserStrategyBean).setResourceLoader(resourceLoader);
		}
	}
}
 
Example 2
Source File: ParserStrategyUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Invoke {@link BeanClassLoaderAware}, {@link BeanFactoryAware},
 * {@link EnvironmentAware}, and {@link ResourceLoaderAware} contracts
 * if implemented by the given object.
 */
public static void invokeAwareMethods(Object parserStrategyBean, Environment environment,
		ResourceLoader resourceLoader, BeanDefinitionRegistry registry) {

	if (parserStrategyBean instanceof Aware) {
		if (parserStrategyBean instanceof BeanClassLoaderAware) {
			ClassLoader classLoader = (registry instanceof ConfigurableBeanFactory ?
					((ConfigurableBeanFactory) registry).getBeanClassLoader() : resourceLoader.getClassLoader());
			if (classLoader != null) {
				((BeanClassLoaderAware) parserStrategyBean).setBeanClassLoader(classLoader);
			}
		}
		if (parserStrategyBean instanceof BeanFactoryAware && registry instanceof BeanFactory) {
			((BeanFactoryAware) parserStrategyBean).setBeanFactory((BeanFactory) registry);
		}
		if (parserStrategyBean instanceof EnvironmentAware) {
			((EnvironmentAware) parserStrategyBean).setEnvironment(environment);
		}
		if (parserStrategyBean instanceof ResourceLoaderAware) {
			((ResourceLoaderAware) parserStrategyBean).setResourceLoader(resourceLoader);
		}
	}
}
 
Example 3
Source File: ParserStrategyUtils.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Invoke {@link BeanClassLoaderAware}, {@link BeanFactoryAware},
 * {@link EnvironmentAware}, and {@link ResourceLoaderAware} contracts
 * if implemented by the given object.
 */
public static void invokeAwareMethods(Object parserStrategyBean, Environment environment,
		ResourceLoader resourceLoader, BeanDefinitionRegistry registry) {

	if (parserStrategyBean instanceof Aware) {
		if (parserStrategyBean instanceof BeanClassLoaderAware) {
			ClassLoader classLoader = (registry instanceof ConfigurableBeanFactory ?
					((ConfigurableBeanFactory) registry).getBeanClassLoader() : resourceLoader.getClassLoader());
			((BeanClassLoaderAware) parserStrategyBean).setBeanClassLoader(classLoader);
		}
		if (parserStrategyBean instanceof BeanFactoryAware && registry instanceof BeanFactory) {
			((BeanFactoryAware) parserStrategyBean).setBeanFactory((BeanFactory) registry);
		}
		if (parserStrategyBean instanceof EnvironmentAware) {
			((EnvironmentAware) parserStrategyBean).setEnvironment(environment);
		}
		if (parserStrategyBean instanceof ResourceLoaderAware) {
			((ResourceLoaderAware) parserStrategyBean).setResourceLoader(resourceLoader);
		}
	}
}
 
Example 4
Source File: NettyEmbeddedAutoConfiguration.java    From spring-boot-protocol with Apache License 2.0 6 votes vote down vote up
/**
 * Add the HTTP protocol registry
 * @param factory factory
 * @param resourceLoader resourceLoader
 * @return HttpServletProtocol
 */
@Bean("httpServletProtocol")
@ConditionalOnMissingBean(HttpServletProtocol.class)
public HttpServletProtocol httpServletProtocol(ConfigurableBeanFactory factory, ResourceLoader resourceLoader) {
    Class<? extends Executor> serverHandlerExecutorClass = nettyProperties.getHttpServlet().getServerHandlerExecutor();
    Supplier<Executor> serverHandlerExecutor = null;
    if(serverHandlerExecutorClass != null){
        serverHandlerExecutor = () -> factory.getBean(serverHandlerExecutorClass);
    }

    HttpServletProtocolSpringAdapter protocol = new HttpServletProtocolSpringAdapter(nettyProperties,serverHandlerExecutor,resourceLoader.getClassLoader());
    NettyProperties.HttpServlet http = nettyProperties.getHttpServlet();
    protocol.setMaxInitialLineLength(http.getMaxHeaderLineSize());
    protocol.setMaxHeaderSize(http.getMaxHeaderSize());
    protocol.setMaxContentLength(http.getMaxContentSize());
    protocol.setMaxChunkSize(http.getMaxChunkSize());

    factory.addBeanPostProcessor(protocol);
    return protocol;
}
 
Example 5
Source File: FunctionalInstallerListener.java    From spring-init with Apache License 2.0 6 votes vote down vote up
public static void invokeAwareMethods(Object target, Environment environment, ResourceLoader resourceLoader,
		BeanDefinitionRegistry registry) {

	if (target instanceof Aware) {
		if (target instanceof BeanClassLoaderAware) {
			ClassLoader classLoader = (registry instanceof ConfigurableBeanFactory
					? ((ConfigurableBeanFactory) registry).getBeanClassLoader() : resourceLoader.getClassLoader());
			if (classLoader != null) {
				((BeanClassLoaderAware) target).setBeanClassLoader(classLoader);
			}
		}
		if (target instanceof BeanFactoryAware && registry instanceof BeanFactory) {
			((BeanFactoryAware) target).setBeanFactory((BeanFactory) registry);
		}
		if (target instanceof EnvironmentAware) {
			((EnvironmentAware) target).setEnvironment(environment);
		}
		if (target instanceof ResourceLoaderAware) {
			((ResourceLoaderAware) target).setResourceLoader(resourceLoader);
		}
	}
}
 
Example 6
Source File: ConditionEvaluator.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Nullable
private ClassLoader deduceClassLoader(@Nullable ResourceLoader resourceLoader,
		@Nullable ConfigurableListableBeanFactory beanFactory) {

	if (resourceLoader != null) {
		ClassLoader classLoader = resourceLoader.getClassLoader();
		if (classLoader != null) {
			return classLoader;
		}
	}
	if (beanFactory != null) {
		return beanFactory.getBeanClassLoader();
	}
	return ClassUtils.getDefaultClassLoader();
}
 
Example 7
Source File: ConditionEvaluator.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Nullable
private ClassLoader deduceClassLoader(@Nullable ResourceLoader resourceLoader,
		@Nullable ConfigurableListableBeanFactory beanFactory) {

	if (resourceLoader != null) {
		ClassLoader classLoader = resourceLoader.getClassLoader();
		if (classLoader != null) {
			return classLoader;
		}
	}
	if (beanFactory != null) {
		return beanFactory.getBeanClassLoader();
	}
	return ClassUtils.getDefaultClassLoader();
}
 
Example 8
Source File: ConditionEvaluator.java    From spring-init with Apache License 2.0 5 votes vote down vote up
@Nullable
private ClassLoader deduceClassLoader(@Nullable ResourceLoader resourceLoader,
		@Nullable ConfigurableListableBeanFactory beanFactory) {

	if (resourceLoader != null) {
		ClassLoader classLoader = resourceLoader.getClassLoader();
		if (classLoader != null) {
			return classLoader;
		}
	}
	if (beanFactory != null) {
		return beanFactory.getBeanClassLoader();
	}
	return ClassUtils.getDefaultClassLoader();
}
 
Example 9
Source File: SimpleConditionService.java    From spring-init with Apache License 2.0 5 votes vote down vote up
public SimpleConditionService(BeanDefinitionRegistry registry, ConfigurableListableBeanFactory beanFactory,
		Environment environment, ResourceLoader resourceLoader) {
	this.beanFactory = beanFactory;
	this.evaluator = new ConditionEvaluator(registry, environment, resourceLoader);
	this.classLoader = resourceLoader.getClassLoader();
	String metadataFactory = MetadataReaderFactory.class.getName();
	this.metadataReaderFactory = beanFactory.containsSingleton(metadataFactory)
			? (MetadataReaderFactory) beanFactory.getSingleton(metadataFactory)
			: new CachingMetadataReaderFactory(this.classLoader);
}
 
Example 10
Source File: SpringContextUtil.java    From galaxy with Apache License 2.0 4 votes vote down vote up
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
    this.classLoader= resourceLoader.getClassLoader();
}
 
Example 11
Source File: CodelessScannerRegistrar.java    From sca-best-practice with Apache License 2.0 4 votes vote down vote up
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
    this.classLoader = resourceLoader.getClassLoader();
}
 
Example 12
Source File: SpringContextUtil.java    From tcc-transaction with Apache License 2.0 4 votes vote down vote up
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
    this.classLoader= resourceLoader.getClassLoader();
}
 
Example 13
Source File: AnnotatedVelocityToolsScanner.java    From velocity-spring-boot-project with Apache License 2.0 4 votes vote down vote up
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
    this.provider.setResourceLoader(resourceLoader);
    this.classLoader = resourceLoader.getClassLoader();
}
 
Example 14
Source File: CodelessDaoFactoryBean.java    From sca-best-practice with Apache License 2.0 4 votes vote down vote up
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
    this.classLoader = resourceLoader.getClassLoader();
}
 
Example 15
Source File: ResourceEntityResolver.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Create a ResourceEntityResolver for the specified ResourceLoader
 * (usually, an ApplicationContext).
 * @param resourceLoader the ResourceLoader (or ApplicationContext)
 * to load XML entity includes with
 */
public ResourceEntityResolver(ResourceLoader resourceLoader) {
	super(resourceLoader.getClassLoader());
	this.resourceLoader = resourceLoader;
}
 
Example 16
Source File: ResourceEntityResolver.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a ResourceEntityResolver for the specified ResourceLoader
 * (usually, an ApplicationContext).
 * @param resourceLoader the ResourceLoader (or ApplicationContext)
 * to load XML entity includes with
 */
public ResourceEntityResolver(ResourceLoader resourceLoader) {
	super(resourceLoader.getClassLoader());
	this.resourceLoader = resourceLoader;
}
 
Example 17
Source File: ResourceEntityResolver.java    From blog_demos with Apache License 2.0 2 votes vote down vote up
/**
 * Create a ResourceEntityResolver for the specified ResourceLoader
 * (usually, an ApplicationContext).
 * @param resourceLoader the ResourceLoader (or ApplicationContext)
 * to load XML entity includes with
 */
public ResourceEntityResolver(ResourceLoader resourceLoader) {
	super(resourceLoader.getClassLoader());
	this.resourceLoader = resourceLoader;
}
 
Example 18
Source File: ResourceEntityResolver.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a ResourceEntityResolver for the specified ResourceLoader
 * (usually, an ApplicationContext).
 * @param resourceLoader the ResourceLoader (or ApplicationContext)
 * to load XML entity includes with
 */
public ResourceEntityResolver(ResourceLoader resourceLoader) {
	super(resourceLoader.getClassLoader());
	this.resourceLoader = resourceLoader;
}
 
Example 19
Source File: ResourceEntityResolver.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Create a ResourceEntityResolver for the specified ResourceLoader
 * (usually, an ApplicationContext).
 * @param resourceLoader the ResourceLoader (or ApplicationContext)
 * to load XML entity includes with
 */
public ResourceEntityResolver(ResourceLoader resourceLoader) {
	super(resourceLoader.getClassLoader());
	this.resourceLoader = resourceLoader;
}