use of org.springframework.core.io.ResourceLoader in project spring-data-commons by spring-projects.
the class AnnotatedTypeScanner method findTypes.
public Set<Class<?>> findTypes(Iterable<String> basePackages) {
ClassPathScanningCandidateComponentProvider provider = new InterfaceAwareScanner(considerInterfaces);
if (resourceLoader != null) {
provider.setResourceLoader(resourceLoader);
}
if (environment != null) {
provider.setEnvironment(environment);
}
for (Class<? extends Annotation> annotationType : annotationTypess) {
provider.addIncludeFilter(new AnnotationTypeFilter(annotationType, true, considerInterfaces));
}
Set<Class<?>> types = new HashSet<>();
ResourceLoader loader = resourceLoader;
ClassLoader classLoader = loader == null ? null : loader.getClassLoader();
for (String basePackage : basePackages) {
for (BeanDefinition definition : provider.findCandidateComponents(basePackage)) {
String beanClassName = definition.getBeanClassName();
if (beanClassName == null) {
throw new IllegalStateException(String.format("Unable to obtain bean class name from bean definition %s!", definition));
}
try {
types.add(ClassUtils.forName(beanClassName, classLoader));
} catch (ClassNotFoundException o_O) {
throw new IllegalStateException(o_O);
}
}
}
return types;
}
use of org.springframework.core.io.ResourceLoader in project spring-data-commons by spring-projects.
the class RepositoryBeanDefinitionParser method parse.
/*
* (non-Javadoc)
* @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
*/
@Nullable
public BeanDefinition parse(Element element, ParserContext parser) {
XmlReaderContext readerContext = parser.getReaderContext();
try {
ResourceLoader resourceLoader = ConfigurationUtils.getRequiredResourceLoader(readerContext);
Environment environment = readerContext.getEnvironment();
BeanDefinitionRegistry registry = parser.getRegistry();
XmlRepositoryConfigurationSource configSource = new XmlRepositoryConfigurationSource(element, parser, environment);
RepositoryConfigurationDelegate delegate = new RepositoryConfigurationDelegate(configSource, resourceLoader, environment);
RepositoryConfigurationUtils.exposeRegistration(extension, registry, configSource);
for (BeanComponentDefinition definition : delegate.registerRepositoriesIn(registry, extension)) {
readerContext.fireComponentRegistered(definition);
}
} catch (RuntimeException e) {
handleError(e, element, readerContext);
}
return null;
}
use of org.springframework.core.io.ResourceLoader in project spring-security by spring-projects.
the class WebXmlJ2eeDefinedRolesRetrieverTests method testRole1To4Roles.
@Test
public void testRole1To4Roles() throws Exception {
List<String> ROLE1TO4_EXPECTED_ROLES = Arrays.asList("Role1", "Role2", "Role3", "Role4");
final Resource webXml = new ClassPathResource("webxml/Role1-4.web.xml");
WebXmlMappableAttributesRetriever rolesRetriever = new WebXmlMappableAttributesRetriever();
rolesRetriever.setResourceLoader(new ResourceLoader() {
@Override
public ClassLoader getClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
@Override
public Resource getResource(String location) {
return webXml;
}
});
rolesRetriever.afterPropertiesSet();
Set<String> j2eeRoles = rolesRetriever.getMappableAttributes();
assertThat(j2eeRoles).containsAll(ROLE1TO4_EXPECTED_ROLES);
}
use of org.springframework.core.io.ResourceLoader in project spring-security by spring-projects.
the class SecurityMockMvcRequestPostProcessors method x509.
/**
* Finds an X509Cetificate using a resoureName and populates it on the request.
* @param resourceName the name of the X509Certificate resource
* @return the
* {@link org.springframework.test.web.servlet.request.RequestPostProcessor} to use.
* @throws IOException
* @throws CertificateException
*/
public static RequestPostProcessor x509(String resourceName) throws IOException, CertificateException {
ResourceLoader loader = new DefaultResourceLoader();
Resource resource = loader.getResource(resourceName);
InputStream inputStream = resource.getInputStream();
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
X509Certificate certificate = (X509Certificate) certFactory.generateCertificate(inputStream);
return x509(certificate);
}
use of org.springframework.core.io.ResourceLoader in project spring-framework by spring-projects.
the class HttpServletBean method init.
/**
* Map config parameters onto bean properties of this servlet, and
* invoke subclass initialization.
* @throws ServletException if bean properties are invalid (or required
* properties are missing), or if subclass initialization fails.
*/
@Override
public final void init() throws ServletException {
// Set bean properties from init parameters.
PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties);
if (!pvs.isEmpty()) {
try {
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext());
bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment()));
initBeanWrapper(bw);
bw.setPropertyValues(pvs, true);
} catch (BeansException ex) {
if (logger.isErrorEnabled()) {
logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex);
}
throw ex;
}
}
// Let subclasses do whatever initialization they like.
initServletBean();
}
Aggregations